How to make XML strings bold, underlined etc? How to make XML strings bold, underlined etc? xml xml

How to make XML strings bold, underlined etc?


Try wrapping your marked up text in CDATA tags. For example:

<string name="ss"><![CDATA[<b>Bold.</b> <u>Underlined.</u> <i>Italic.</i> <big>Big.</big> <small>Small</small>]]></string>

And then use Html.fromHtml wherever you're wanting to display it:

Html.fromHtml(getString(R.string.ss))


This problem has been driving me crazy for ages. It's something sooo simple that you just want it to work!!!

Anyway I've found an answer here at http://www.coderzheaven.com/2011/06/19/styling-text-in-android-through-xml/

The key is to load the resource as a CharSequence using getResources().getText(R.string.xxxx) this will retain all the style information and allow you to use inline styling tags.My mistake was using getString() because when loading your resource getString() will cause the string to lose all its style information.


exemple:

<string name="ss"><font size="15"><b>Parrainage</b></font><u>subscribe</u></string>

b = bold et u = underline .....etc