Superscript and Subscript in Android App XML

13,246

Solution 1

I found out how

In the XML file the code should be like this :

<value column="Back" null="false">H&lt;sub&gt;2&lt;/sub&gt;</value>

So that the parced string value is "H<sub>2</sub>" then in the java code :

TextView textview.setText(Html.fromHtml(YourString);

and for superscript use "sup" instead of "sub"

Solution 2

You can use <small> tag along with <sub> or <sup> tags to decrease the size of the text.

For example:<sup><small>your-string</small></sup>

If you want to still decrease the size of text,you add <small> tag once more like this<sup><small><small>your-string</small></small></sup>

I'm using android studio and it is working perfectly for me !

Solution 3

i found this method useful for me.

strings.xml

<string name="your_string">H<sub>2</sub></string>
Share:
13,246
xSooDx
Author by

xSooDx

Updated on August 06, 2022

Comments

  • xSooDx
    xSooDx almost 2 years

    I am parsing data from an XML file which has subscript and superscript characters in them which I got from the character map. Like so:

    <value column="Back" null="false">H₂</value>
    

    but when I display it on a textview in Android it gives me this 'Hâ,,'

    How can I fix this and display it properly in my app?