How to change text color programmatically in kotlin

Viewed 6352

I found similar questions on stakeOverFlow, but the answers did not help me

file: values.xml

<color name= "orange_or">#EC7000</color>

my textView in kotlin

private val myText: TextView bi bindView(R.id.my_text)

if (conditionTrue) {
    //my text color = orange_or
}

how would I change this textView to that color from the values.xml file in the kotlin?

1 Answers

You can use:

   //with a color  
   myText.setTextColor(ContextCompat.getColor(this,R.color.orange_or))
   //with a selector
   myText.setTextColor(AppCompatResources.getColorStateList(this, R.color.xxx))
Related