HTML in string resource?

You can also surround your html in a CDATA block as well and getString() will return your actual HTML. Like such:

<string name="foo"><![CDATA[Foo Bar <a href="https://stackoverflow.com/questions/2667319/foo?id=%s">baz</a> is cool]]></string>

Now when you perform a getString(R.string.foo) the string will be HTML. If you need to render the HTML (with the link as shown) via a clickable TextView you’d need to perform a Html.fromHtml(...) call to get the spannable text.

Leave a Comment