你如何在 Android XML 中给文本加下划线? [英] How do you underline a text in Android XML?

查看:72
本文介绍了你如何在 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>.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆