安卓 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" /><!-- 结束符 -->
添加结束符后,最后两行文本将正常显示为红色。
以上就是Android XML 文本着色为何失效?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号