1

so I got a string like this:

<string name="colorThis">This is red.</string>

I'd like to have 'This' in red. Is there any possible way of doing so? I find out that regular XML-formatting doesn't work. Also I know how to color the full string. But a single word? Halp plz

momo
  • 119
  • 3
  • 10

3 Answers3

2

You can use html for this. Try like this:

<string name="colorThis"><![CDATA[<font color="red">This is red.</font>]]></string>

or like this

<string name="colorThis"><![CDATA[<font color="#FF0000">This is red.</font>]]></string>

and then set your text like this: yourTextView.setText(Html.fromHtml(getResources().getString(R.string.colorThis)));

Damien R.
  • 3,383
  • 1
  • 21
  • 32
1

you can try with Html.fromHtml and, of course, using an html tag. An alternative could be to use a SpannableString but, of course, you have to do it programmatically

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

You can use SpannableStringBuilder for different colors on a string. Pls check this link

Community
  • 1
  • 1
Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48