Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set two different colors for text in TextView in XML? [duplicate]

I have two words inside TextView :

Hello world.

Now I want to colorize world to red color. How I can do that ONLY in XML itself without using java code (without using Html.fromHtml() as well)

like image 407
Sergey Shustikov Avatar asked Sep 29 '16 10:09

Sergey Shustikov


People also ask

How do I add color to text in XML?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .


1 Answers

You can use font tag in string.xml as

<string name="hello">Hello <font fgcolor="red">World</font></string>
like image 112
aastha gupta Avatar answered Sep 21 '22 06:09

aastha gupta