Superscript and subscript in XML Android application

I am processing data from an XML file that has indexes and superscript characters that I received from a character map. For instance:

<value column="Back" null="false">Hโ‚‚</value> 

but when I show it in text form in android, it gives me this "Hรข,"

How can I fix this and display it correctly in my application?

+4
source share
4 answers

I found out how

In the XML file, the code should look like this:

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

Thus, the value of the string with the character "H<sub>2</sub>" then in the java code:

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

and for superscript instead of "sub"

use "sup"
+6
source

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

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

If you want to reduce the size of the text, add the <small> tag again, like this <sup><small><small>your-string</small></small></sup>

I use android studio and it works great for me!

+1
source

You can change it easier, just write to @strings or where you want <sub>your-string-here</sub> for the index or <sup>your-string-here</sup> . The lowercase letters (of your word) are still the same size as your text. You need to reduce its size. To do this, use where the number indicates the size of the desired text.

0
source

I found this method useful to me.

strings.xml

 <string name="your_string">H<sub>2</sub></string> 
0
source

All Articles