How to use "setTextColor(hexaValue)" on Kotlin for Android,

textView.setTextColor(Color.parseColor("#0aad3f"))

Oxff000000 is resolved to Long in Kotlin so right now there is no way to use this literal as is, however 0xff000000.toInt() will give you exactly the same result as -0x1000000 so you can use .toInt() approach. Under the hood, it's the equivalent of (int)4278190080L Java cast.

Also, with Kotlin extensions you can write a simple property like that

var TextView.textColor: Long
get() {
    //... not important
}
set(value: Long) {
    this.setTextColor(value.toInt())
}

and you'll be able to use a more concise syntax textView.textColor = 0xff000000

UPDATE: As of Kotlin 1.3 it will be possible to use concise syntax like that 0xff000000u See: Jetbrains blog and the original proposal


You can try this to set color of your text programmatically.

textview.textColor=Color.parseColor("#22aadd")