TextView、Button控件文本添加下划线最简单的方式就是在strings.xml资源文件中定义html格式的字符串,亦即添加<u>标签。
layout布局文件中:
<TextView
android:id="@+id/txt_underline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/underline"
android:textColor="#FFE5E5E5"
android:textSize="20sp" />
strings.xml资源文件中:
<string name="underline"><u>下划线测试</u></string>
注:必须在strings.xml文件中定义,在layout布局文件中直接添加<u>标签会出现编译错误。
本文介绍了一种在Android应用中为TextView和Button控件文本添加下划线的简便方法。通过在strings.xml资源文件中定义包含<u>标签的html格式字符串,可以在布局文件中直接引用,实现文本下划线效果。注意,此方法不支持在布局文件内直接使用<u>标签。
823

被折叠的 条评论
为什么被折叠?



