我正在使用 Eclipse 靛 o,在2个模拟器(2.2和3.0)上进行测试。
下面的代码显示了我现在正在测试的内容,但是当试图运行模拟器时,设置文本大小在屏幕上显示不出任何东西。(如果我注释掉文本大小,文本显示为红色)。我认为 Eclipse 并没有重新构建代码,但是我添加了一行代码来添加蓝色的背景,并且成功了。我试过在设置文本之后设置文本大小,但仍然没有成功。密码如下。谢谢你的帮助! (免责声明)-我试图远离 xml。因为我已经知道 Java 了,我不想再依赖它了。
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;
public class TestAndroidvs2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setTextColor(Color.RED);
text.setTextSize(2);
text.setBackgroundColor(Color.BLUE);
text.setText("Hello Android");
setContentView(text);
}
}