机器人的TextView:设置背景颜色动态不起作用机器人、不起作用、颜色、背景

2023-09-12 10:45:30 作者:遗留在唇边の吻

设置一个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(我的文字);
 
PS教程 看国外大神是如何用PS将美女变成逼真机器人

解决方案

使用 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);