如何在 Android XML 中为文本添加下划线?

编程入门 行业动态 更新时间:2024-10-20 15:59:48
本文介绍了如何在 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 中为文本添加下划线?

本文发布于:2023-06-07 21:58:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568514.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:下划线   中为   文本   如何在   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!