0

I am making a calculator and I need to add a -1 to the power of cos, to signify inverse cos, and I need to display this in my EditText like this. Any ideas are greatly appreciated. Also, I am using Android Studio.

Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
Adam
  • 63
  • 8
  • yeah sorry about that, I didn't find that when I was looking... I tried the way posted there but it didn't work... when I try calling the string from the strings file, I get a null pointer exception – Adam May 29 '16 at 03:23
  • Ok... I figured the exception out... but when I use the HTML code it doesn't superscript it it just displays the -1 normally – Adam May 29 '16 at 03:31
  • I figured it out, my case was different because i was using a string builder and that eliminated all html changes – Adam May 29 '16 at 18:03

2 Answers2

0
((EditText) findViewById(R.id.editText)).setText(Html.fromHtml("cos<sup>-1</sup>"));
Linh
  • 57,942
  • 23
  • 262
  • 279
Mahbub Mukul
  • 333
  • 3
  • 18
0

You can use SpannableString to customize the text at various points in the strong. Please see the following answer for Textview which you can adapt to EditText https://stackoverflow.com/a/14981952/4419474

Community
  • 1
  • 1
Chebyr
  • 2,171
  • 1
  • 20
  • 30
  • Thanks... I used this method and have made the -1 smaller, but it is a subscript not a superscript – Adam May 29 '16 at 17:46