在 Android textSwitcher 中使用上标
我无法让我的 textSwitcher 支持上标文本。无论我尝试什么,它都会显示为常规大小的文本。
这是我尝试过的:
Spanned span = Html.fromHtml("<sup>TM</sup>");
String subscript = span.toString();
mSwitcher.setText(getText(R.string.desc_about1) + subscript);
然后我尝试将其设置在 XML 字符串文件中:
<string name="desc_about1">Android<sup><small>TM</small></sup></string>
这些都不起作用。还有别的办法吗?
我的textSwitcher代码供参考:
<TextSwitcher android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
@Override
public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.LEFT);
t.setTextSize(18);
return t;
}
谢谢大家!
I can't manage to get my textSwitcher to be able to support superscript text. No matter what I try it shows up as regular size text.
Here is what I've tried:
Spanned span = Html.fromHtml("<sup>TM</sup>");
String subscript = span.toString();
mSwitcher.setText(getText(R.string.desc_about1) + subscript);
Then I tried setting it in the XML string file:
<string name="desc_about1">Android<sup><small>TM</small></sup></string>
Neither one of these will work. Is there another way?
My textSwitcher code for reference:
<TextSwitcher android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
@Override
public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.LEFT);
t.setTextSize(18);
return t;
}
Thanks all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的第一个示例对我来说看起来不正确,请尝试以下操作:
对我有用的完整示例:
}
如果您想使用 strings.xml 来存储文本:
只需确保您传递到 setText 的最新内容是 fromHtml 输出。
Your first example looks incorrect for me, try this instead:
Full example that works for me:
}
And if you want to use strings.xml to store you texts:
Just make sure that latest thing you pass into setText is fromHtml output.
我知道上一个条目是两年多前被接受的答案,但我添加了一个略有不同的解决
方案贸易;转换为字符集中的单个字符,而不是像 ™ 中那样更小的上标 TM
I know that the previous entry was an accepted answer just over 2 years ago, but I'm adding a slightly different solution
The & trade; converts to a single character from the character set rather than a smaller and super-script TM as in ™