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,642
  • 9
  • 58
  • 78
Adam
  • 51
  • 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
  • 51,033
  • 19
  • 228
  • 256
Mahbub Mukul
  • 323
  • 3
  • 17
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,161
  • 1
  • 18
  • 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