How can you print a string with a subscript or superscript? Can you do this without an external library? I want this to display in a TextView
in Android.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
The HTML.fromHTML(String) was deprecated as of API 24. They say to use this one instead, which supports flags as a parameter. So to go off of the accepted answer:
And if you want code that considers pre-24 API's as well:
This answer was derived from: https://stackoverflow.com/a/37905107/4998704
The flags and other documentation can be found here: https://developer.android.com/reference/android/text/Html.html
In the
strings.xml
files, you can just use the HTML<sup>3</sup>
tag. Work perfectly for meEXAMPLE
They are called Unicode characters, and Android
TextView
supports them. Copy the super/sub-script you want from this Wiki: https://en.wikipedia.org/wiki/List_of_Unicode_characters#Superscripts_and_SubscriptsThe Accepted answer is deprecated now. So please go through this piece of code. I got this from some website. I forgot the name but anyway thanks for this good piece of working code.
Note : Always put
android:textAllCaps="false"
of your spantext.To all people asking, if you want to make it smaller besides of making super or subscript, you just need to add tag as well. EX:
Example: