如何在 Android XML 中为文本添加下划线? [英] How do you underline a text in Android XML?
本文介绍了如何在 Android XML 中为文本添加下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 XML 文件中为文本添加下划线?我在 textStyle
中找不到选项.
How do you underline a text in an XML file? I can't find an option in textStyle
.
推荐答案
如果你使用的是字符串资源xml文件(支持HTML标签),可以使用<b></b>
, <i></i>
和 <u></u>
.
If you are using a string resource xml file (supports HTML tags), it can be done using<b> </b>
, <i> </i>
and <u> </u>
.
<resources>
<string name="your_string_here">
This is an <u>underline</u>.
</string>
</resources>
如果你想在代码中使用下划线:
If you want to underline something from code use:
TextView tv = (TextView) view.findViewById(R.id.tv);
SpannableString content = new SpannableString("Content");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tv.setText(content);
希望对你有帮助
这篇关于如何在 Android XML 中为文本添加下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文