以编程方式设置背景颜色的android textview似乎不工作。 我是我想念的东西!android TextView:动态设置背景颜色不起作用
TextView et = new TextView(activity);
et.setText("350");
et.setBackgroundColor(R.color.white);
我也有我的资源文件(colors.xml)/值文件夹
<resources>
<color name="white">#ffffffff</color>
<color name="black">#ff000000</color>
</resources>
[编辑]: 此外,设置文本的颜色会导致TextView中消失。
TextView c1 = new TextView(activity);
c1.setTextColor(R.color.solid_red);
c1.setText("My Text");
android API真的是一些东西,为什么不能抛出一个错误呢? – Tawani 2009-09-23 17:05:58
因为这不是错误。 setBackgroundColor()采用数字形式的颜色(例如,红色为0xFFFF0000)。 R.color.white也是一个数字。 – CommonsWare 2009-09-23 17:15:25
D'oh!对于枚举而言,这绝对可以做得更好,而不是无处不在的整数。感谢你的回答。 – 2012-09-02 15:21:43