我在stakeOverFlow 上发现了类似的问题,但答案对我没有帮助
文件:values.xml
<color name= "orange_or">#EC7000</color>
我在 kotlin 中的 textViewprivate val myText: TextView bi bindView(R.id.my_text)
if (conditionTrue) {
//my text color = orange_or
}
如何从 kotlin 中的 values.xml 文件中将此 textView 更改为该颜色?
最佳答案
您可以使用:
//with a color
myText.setTextColor(ContextCompat.getColor(this,R.color.orange_or))
//with a selector
myText.setTextColor(AppCompatResources.getColorStateList(this, R.color.xxx))
关于android - 如何在 kotlin 中以编程方式更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63837502/