Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write the "to the power" and some text like as shown in Java or Android?

Tags:

java

android

As in the images shown below, is it possible to write code to write "to the power" in Android or Java?

enter image description here

enter image description here

like image 671
Android Killer Avatar asked Oct 11 '11 13:10

Android Killer


1 Answers

Something like:

TextView t = (TextView) findViewById(R.id.text);
t.setText(Html.fromHtml("7<sup>2</sup>"));

According to Android documentation on their FAQ, you can always do this using a string resource, but if you do it on the fly you must make sure the TextView is using Spannable storage (always true if it's an EditText for example).

See Selecting, Highlighting, or Styling Portions of Text in the Android Common Tasks.

like image 192
JRL Avatar answered Oct 13 '22 01:10

JRL