Hidde
Hidde

Reputation: 11961

Using HTML in my TextView

I want to use HTML in my TextView (sub- and superscript). The problem is, that I only want to use XML when coding my UI elements: I don't want to use HTML.fromHtml(...);.

The string I have in my resources is the following code:

...
<string name="buttonY1"><![CDATA[<html><i>Y</i><sup>2</sup></html>]]></string>
...

The XML code is:

...
<TextView android:text="@string/buttonY1"
                      android:textSize="20sp"
                      android:gravity="center_horizontal"></TextView>
...

When I debug my app, the text shows plain text (with the tags still in it), and not the parsed HTML. Any solutions?

Upvotes: 0

Views: 1379

Answers (1)

Mirko Lindner
Mirko Lindner

Reputation: 628

Simple remove the CDATA part, just include the tags as they are e.g.:

<string name="lorem_short"><sub>Lorem</sub> ipsum dolor <sup>sit</sup> amet, consetetur sadipscing elitr</string>

Upvotes: 2

Related Questions