Search code examples
androidstringtextview

Change the color of a part of a TextView in strings.xml


In my android app with Kotlin, I created a layout in which there's a TextView that shows some text. For the text I have an item in strings.xml where I want to change the color of part of this Text, I tried the following code :

<string name="description">the product is <font fgcolor="green"> free </font></string>

But, The color didn't change. I just want to change the color of "free" to green, can someone explain how I can achieve this?


Solution

  • Use <font color="#008000">free</font> instead. According to the documentation, the correct attribute name is color and it only supports hex codes.