1

I have a created a string in my string.xml file and would like to change the color of the words Excitement, Adventurous in the sentence to yellow. I have tried to add <font color="yellow">Excitement, Adventourous</font> but this does nothing.

string.xml

 <string name="screen114_3">EMOTION Driver5- UNCERTAINTY/VARIETY (Surprise, Diversity, Challenge,<font color="yellow">Excitement, Adventurous</font>, Wild)
</string>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
AnonymousZA
  • 121
  • 1
  • 11
  • 2
    I'm unsure about this, but I think you have to use `Html.fromHtml(getString(R.string.screen114_3))` here – Zun Jul 09 '18 at 07:43
  • Try this https://stackoverflow.com/questions/7221930/change-text-color-of-one-word-in-a-textview – Ankita Jul 09 '18 at 07:45

2 Answers2

0

Try This:

String text = "EMOTION Driver5- UNCERTAINTY/VARIETY (Surprise, Diversity, Challenge,<font color="yellow">Excitement, Adventurous</font>"
mTextView.setText(Html.fromHtml(text));
Shubham Vala
  • 1,024
  • 7
  • 18
0

Use CDATA , Try this

<string name="screen114_3"><![CDATA[EMOTION Driver5- UNCERTAINTY/VARIETY (Surprise, Diversity, Challenge,<font color="yellow">Excitement, Adventurous</font>, Wild]]></string>

then add

String colouredString = getResources().getString(R.string.screen114_3);
    textview.setText(Html.fromHtml(colouredString));
Navneet Krishna
  • 5,009
  • 5
  • 25
  • 44