Superscript and Subscript in Android App XML

戏子无情 提交于 2019-12-23 15:00:18

问题


I am parcing 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?


回答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"




回答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 !




回答3:


You can change it easier than that, just write in @strings or where you want<sub>your-string-here</sub> for subscript or <sup>your-string-here</sup>. The subscripted letters(of your word) still have the same size as your text. You need to decrease it's size. For that, use , where number means the size of the text you want.




回答4:


i found this method useful for me.

strings.xml

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


来源:https://stackoverflow.com/questions/15817365/superscript-and-subscript-in-android-app-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!