In XML, we can set a text color by the textColor
attribute, like android:textColor=\"#FF0000\"
. But how do I change it by coding?
I tried s
Add these to make changing text color simpler
myView.textColor = Color.BLACK // or Color.parseColor("#000000"), etc.
var TextView.textColor: Int
get() = currentTextColor
set(@ColorInt color) {
setTextColor(color)
}
myView.setTextColorRes(R.color.my_color)
fun TextView.setTextColorRes(@ColorRes colorRes: Int) {
val color = ContextCompat.getColor(context, colorRes)
setTextColor(color)
}