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.
views:
310answers:
4
A:
If you mean printing a String in Swing or AWT, then take a look at the TextAttribute
class, which is used in conjunction with the Font
class. It has a SUPERSCRIPT
Integer attribute.
I think you'll need to give a little more detail as to where exactly you're printing this String.
Noel M
2010-08-22 21:25:18
I clarified that I want this in a TextView in Android.
Mohit Deshpande
2010-08-22 21:51:40
A:
For android, I'm not sure there's a way to do this in a TextView. You may want to use a webview instead so you can use html.
Falmarri
2010-08-22 21:55:32
+1
A:
I found this article on how to use a Spannable
or in a string resource file: <sup>
or <sub>
for superscript and subscript, respectively.
Mohit Deshpande
2010-08-22 22:01:24
+7
A:
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("X<sup>2</sup>"));
or
http://developer.android.com/intl/zh-TW/guide/appendix/faq/commontasks.html#selectingtext
Konstantin Burov
2010-08-22 22:04:22