设置一个Android的TextView的背景颜色编程方式似乎并没有工作。 我我失去了一些东西!
的TextView等=新的TextView(活动);
et.setText(350);
et.setBackgroundColor(R.color.white);
我也有这个文件(colors.xml)在我RES /值文件夹
<资源>
<颜色名称=白>#FFFFFFFF< /彩色>
<颜色名称=黑>#FF000000< /彩色>
< /资源>
: 此外,设置文本的颜色会导致TextView中消失。
TextView的C1 =新的TextView(活动);
c1.setTextColor(R.color.solid_red);
c1.setText(我的文字);
解决方案
使用 et.setBackgroundResource(R.color.white);
Setting the background color programatically of an android TextView doesn't seem to work. I'm I missing something!
TextView et = new TextView(activity);
et.setText("350");
et.setBackgroundColor(R.color.white);
I also have this file (colors.xml) in my res/values folder
<resources>
<color name="white">#ffffffff</color>
<color name="black">#ff000000</color>
</resources>
[EDIT]: Also, setting the text color causes the TextView to disappear.
TextView c1 = new TextView(activity);
c1.setTextColor(R.color.solid_red);
c1.setText("My Text");
解决方案
Use et.setBackgroundResource(R.color.white);