Subscript and Superscript a String in Android

后端 未结 15 1618
面向向阳花
面向向阳花 2020-11-22 09:20

How can you print a string with a subscript or superscript? Can you do this without an external library? I want this to display in a TextView in Android.

15条回答
  •  迷失自我
    2020-11-22 09:59

    If you want to set the superscript from string.xml file try this:

    string resource:

    X<sup>3</sup>
    

    if you want the superscript to be smaller:

    X<sup><small>3</small></sup>
    

    Code:

    textView.setText(Html.fromHtml("Anything you want to put here"+getString(R.string.test_string)));
    

提交回复
热议问题