我正在使用Eclipse Indigo,在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);
}
}