【问题标题】:Custom Text in Android TextView [duplicate]Android TextView中的自定义文本[重复]
【发布时间】:2016-08-18 23:58:17
【问题描述】:

如何实现TextView,文字如下图:

以下解决方案为我提供了详尽的代码。 Subscript and Superscript a String in Android

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

【问题讨论】:

标签: android string android-studio textview string.xml


【解决方案1】:

试试这个:

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

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

    • 谢谢 :) 我得到了答案。
    猜你喜欢
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多