2
MyButton.setText(Html.fromHtml("*  <small><sup>^</sup></small>"));

With Eclipse :

enter image description here

With Android Studio :

enter image description here

It is the same if i use an other method :

SpannableStringBuilder cs = new SpannableStringBuilder("*  ^");    
cs.setSpan(new SuperscriptSpan(), 1, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
cs.setSpan(new RelativeSizeSpan((float) 0.50), 1, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
MyButton.setText(cs);

Muy buid.graddle configuration is :

android {
   compileSdkVersion 18
   buildToolsVersion "21.1.2"

Thanks for your help !

Eric JOYÉ
  • 1,077
  • 9
  • 10

2 Answers2

0

The problem is not migration. I created a new program with AS:

    LinearLayout ly = new LinearLayout(this);

    Button b = new Button(this);
    b.setText(Html.fromHtml("*  <small><sup>^</sup></small>"));

    ly.addView(b);

    TextView tv = new TextView(this);
    tv.setText(Html.fromHtml("*  <small><sup>^</sup></small>"));

    ly.addView(tv);

    setContentView(ly);

Result with Android Studio :

enter image description here

it is working in the textview, but in the button, superscript for "^" character is not present. The same code in eclipse is working well both for the textview and the button.

I'm using AS 1.0.1 and my buid.graddle configuration is :

android {
  compileSdkVersion 21
  buildToolsVersion "21.1.2"

Thanks for your help !

Eric JOYÉ
  • 1,077
  • 9
  • 10
  • @pskink The problem is the same with a simple html tag : b.setText(Html.fromHtml("A A")); – Eric JOYÉ Dec 14 '14 at 11:58
  • 1
    The **SOLUTION** : added **b.setAllCaps(false);** Explanations : http://stackoverflow.com/questions/24880388/cannot-lower-case-button-text-in-android-studio?rq=1 – Eric JOYÉ Dec 14 '14 at 15:14
0

Try this...

Button byButton = new Button(this);
byButton.setText(Html.fromHtml(" * <small><sup> ^ </sup></small>"));
Amitabha Biswas
  • 3,281
  • 1
  • 11
  • 23