Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: display x^y

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!

like image 738
Faur Ioan-Aurel Avatar asked Apr 16 '26 00:04

Faur Ioan-Aurel


2 Answers

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.

like image 146
slayton Avatar answered Apr 17 '26 14:04

slayton


You can use simple html formatting:

String str = number + "<sup>" + anotherNumber + "</sup>";
textView.setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE);
like image 36
alex.zherdev Avatar answered Apr 17 '26 14:04

alex.zherdev