android TextView:动态设置背景颜色不起作用 [英] android TextView: setting the background color dynamically doesn't work
本文介绍了android TextView:动态设置背景颜色不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以编程方式设置 android TextView
的背景颜色似乎不起作用.我错过了什么!
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);
我的 res/values 文件夹中也有这个文件 (colors.xml)
I also have this file (colors.xml) in my res/values folder
<resources>
<color name="white">#ffffffff</color>
<color name="black">#ff000000</color>
</resources>
:此外,设置文本颜色会导致 TextView 消失.
: 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");
推荐答案
使用et.setBackgroundResource(R.color.white);
这篇关于android TextView:动态设置背景颜色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文