如何在代码中设置TextView的文本颜色?在xml中,我们可以通过textColor属性,比如android:textColor="#FF0000"..但是我如何通过编码来改变它呢?我试过这样的方法:holder.text.setTextColor(R.color.Red);哪里holder只是一门课text是类型的TextView..红色是在字符串中设置的RGB值(#FF 0000)。但它显示的是不同的颜色而不是红色。我们可以在setTextColor()中传递什么样的参数?在文档中,它说int,但它是资源引用值还是其他什么?
3 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
<color name="errorColor">#f00</color>
textView.setTextColor(getResources().getColor(R.color.errorColor, getResources().newTheme()));
textView.setTextColor(getResources().getColor(R.color.errorColor, null));
textView.setTextColor(ContextCompat.getColor(context, R.color.errorColor));
- 3 回答
- 0 关注
- 2217 浏览
添加回答
举报
0/150
提交
取消