java - AAPT:错误:“6495ed”与属性背景 (attr) 参考不兼容|颜色
问题描述
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_marginTop="15dp">
<View
android:id="@+id/divider2"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:background="6495ed"/>
</LinearLayout>
这是我的代码,它一直显示与属性背景不兼容的错误
解决方案
android:background="6495ed"
是问题所在。你希望它写成android:background="#6495ed"
更好的做法是将这些颜色值保存在专门保存颜色的 XML 文件中。这些位于您的 res>values 文件夹中,位于 colors.xml 下。
为此,请在 res>values>colors.xml 中添加:
<color name="addala_color_blue">#6495ed</color>
然后在您的布局 XML 中,您将设置:
android:background="@color/addala_color_blue"
或任何你命名的东西。
推荐阅读
- php - MySQL 表值与 php var 相等(然后显示它)
- android - 将来自 Api 的消息显示为通知
- vue.js - Vuejs - returning data from an action
- regex - 跳过前导和尾随空格
- mysql - Convert Selection query to update query
- tensorboardx - tensorboardX add_graph()ImportError: cannot import name 'OperatorExportTypes'
- javascript - 使用 mailto 时在 textarea 中保留换行符
- outlook - 如何在 macOS 中禁用 Outlook 的暗模式?
- css - zoom inside a width fixed div
- python - 多元函数根的求根算法中的两个根之一的括号