
安卓 xml 文件中文本着色的问题
在安卓 xml 布局文件中,可以使用 android:textcolor 指定文本颜色。但是,如果您发现文本颜色不能正常显示,可能是缺少了重要的结束符。
问题:
为什么下图中最后两行文本没有显示为红色?
[图片:https://img2024.cnblogs.com/blog/2991398/202409/2991398-20240920100426742-884504698.png]
答案:
缺少 android:textcolor 的结束符 "/”。正确的代码应该是:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是文本"
android:textColor="#FF0000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这也是文本"
android:textColor="#FF0000" /><!-- 结束符 -->添加结束符后,最后两行文本将正常显示为红色。

