我正在使用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);
}
}
float myTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 18F, context.getResources().getDisplayMetrics());
- Brill Pappin