6

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Android Killer
  • 18,174
  • 13
  • 67
  • 90

2 Answers2

9

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.

JRL
  • 76,767
  • 18
  • 98
  • 146
  • Thanks JRL.But it's not working.I am using button and setting it's text.But the text is coming as " Html.fromHtml("72") " on button.Any idea ? – Android Killer Oct 11 '11 at 13:51
  • I understand your code.I already edited that and given to button text.But it's not working. – Android Killer Oct 11 '11 at 14:07
  • @AndroidPower: look at the provided URL. – JRL Oct 11 '11 at 14:09
  • 2
    @JRL.One thing i forgot to mention.this text is coming from database dynamically.I put Html.fromHtml("72") into database and gave the text to buttom's setText() method.If i am giving directly it is working but from database it is not working.Any idea? – Android Killer Oct 11 '11 at 16:32
  • 1
    @AndroidKiller, that name though.. btw, after fetching the text from the database, put it in string, suppose String a; and then put that in the textview or any place you want to like this: textview.setText(Html.fromHtml(a)); – Tushar Gogna Sep 05 '14 at 11:01
0

You can write HTML Code to show something like this.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Tobias
  • 9,170
  • 3
  • 24
  • 30