0

I am trying to bold a particular word in a string that is stored in strings.xml:

Here is what I would like to have it as:

Future tense: Example: I will be there at 9:00AM

I followed this: Bold words in a string of strings.xml in Android - But didn't get the results.

so I had text in strings.xml like:

<string name="futureText">Future tense: <b>Example:</b> I will be there at 9:00AM</string>

Spanned text = Html.fromHtml(res.getString(R.string.futureText));
questionText.setText (text);

I am not getting any bold for "Example:".

Also how to get the "Example: I will be there at 9:00AM" text to next line? I know in string \n goes to next how about in html format?

What is wrong here?

Community
  • 1
  • 1
TheDevMan
  • 5,914
  • 12
  • 74
  • 144

1 Answers1

1

You can not really read the html tag within the string.xml because it is a default tag within the xml so by the time you read it programatically it wont read the tag but just its text without the tag.

solution:

you need to wrap it in <![CDATA[ ...raw html... ]]> to enable you to read the html tag within the text.

sample:

<string name="futureText">Future tense: <![CDATA[<b>Example:</b>]]> I will be there at 9:00AM</string>
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63