3

Some help please! How can i display raised numbers in a TextView for Android.For example if you want to display some Celsius degrees you can do this:textview.setText(number+"\u2103") and your good to go but i can't find a way to do something like this for number^anothernumber.

Thank you!

Faur Ioan-Aurel
  • 791
  • 1
  • 7
  • 18

3 Answers3

7

Format the string as HTML and then use the html superscript tag <sup>:

textView = (TextView)findViewById(R.id.textView);
String text = "x<sup>y</sup>";
textView.setText(Html.fromHtml(text));

Likewise if you want a subscript use the <sub> tag.

slayton
  • 20,123
  • 10
  • 60
  • 89
3

You can use simple html formatting:

String str = number + "<sup>" + anotherNumber + "</sup>";
textView.setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE);
alex.zherdev
  • 23,914
  • 8
  • 62
  • 56
1

You can use TextViews ability to display html markup, this should work;

textView.setText(android.text.Html.fromHtml("x<sup>y</sup>"));

dmon
  • 30,048
  • 8
  • 87
  • 96
Løkling
  • 558
  • 3
  • 16