How to use HTML tags in an Android TextView

While looking for a way to do some basic formatting of an Android TextView I stumbled across this post Is it possible to have multiple styles inside a TextView?

The result is captured in the following code snippets from string.xml:

<string name="registration_text">
<![CDATA[
<b>Don\'t wait!</b><br/>
Enter your spaceship. Become a spacehead and explore outer space and pile up the resources <b>stuff</b>, <b>black matter</b>
and <b>wisdom</b> in the cargo bay of your spaceship.
]]>

and the corresponding Java one-liner:

((TextView) view.findViewById(R.id.registration_text)).setText(Html.fromHtml(getString(R.string.registration_text)));

Nice.

Show Comments