Android: display x^y
Domanda
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!
Soluzione
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.
Altri suggerimenti
You can use simple html formatting:
String str = number + "<sup>" + anotherNumber + "</sup>";
textView.setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE);
You can use TextViews ability to display html markup, this should work;
textView.setText(android.text.Html.fromHtml("x<sup>y</sup>"));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow