Android TextView 中的自定义文本

Custom Text in Android TextView

如何用如下图的文字实现TextView:

下面的解决方案为我提供了完整的代码。 Subscript and Superscript a String in Android

如何在string.xml中为上图添加字符串?

试试这个:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("4<sup>th</sup>"));

在 strings.xml 中定义您的字符串如下:

<string name="fourth">4&lt;SUP&gt;&lt;/SUP&gt;</string>

如果您需要从代码中调用它,请使用:

myTextView.setText(Html.fromHtml(getString(R.string.fourth)));