Search code examples
androidnumberstextviewraise

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!


Solution

  • 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.