0

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?

4
  • Why you do not want use HTML.fromHtml()? Commented Apr 22, 2012 at 12:35
  • I might, but in my case it doesn't make anything easier. There is more code than the snippets here, and it would take a lot of code to use HTML.fromHtml(). Also, I am just interested if there is any easy way Commented Apr 22, 2012 at 12:38
  • seems you have to use HTML.fromHtml(...);. Commented Apr 22, 2012 at 12:40
  • Look at the first answer, it looks like I don't have to... Commented Apr 22, 2012 at 12:42

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.