![](/img/trans.png)
[英]How to change the text color continuously in android using TextView…?
[英]How to change the text color in a TextView in Android?
所以我试图制作一个代码来更改textView中文本的颜色,我在XML中声明的颜色是这样的:
<color name="right">#FF00FF00</color>
但是,当我尝试更改TextView分数的颜色时,请执行以下操作:
if(input.equalsIgnoreCase(answer+"")){
numRight++;
score.setTextColor(R.color.right);
correct="Correct!";
}
文本消失了。 我引用的颜色有误吗? 为什么不起作用?
您引用不正确:
score.setTextColor(getResources()。getColor(R.color.right);
我希望它能正常工作。
textView1.setTextColor(getResources().getColor(R.color.all));
都是这样的名称,它与xml文件中的颜色定义有关。
<color name= "all">#ffffff</color>
您也可以使用以下格式,它对我来说是正常工作的。
textView1.setTextColor(0xff000000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.