颜色资源错误 [英] Errors in color resources

查看:55
本文介绍了颜色资源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用色彩资源时遇到了皮棉错误.根据文档,以下内容应有效.

I'm getting lint errors attempting to use color resources. According to the documentation, the following should be valid.

<?xml version="1.0" encoding="utf-8"?>
<resources  xmlns:android="http://schemas.android.com/apk/res/android">
    <color name="actionbar_title"></color>
</resources>

但这给出了属性缺少Android名称空间前缀".修改为

But this gives "Attribute is missing the Android namespace prefix". Amending to

<?xml version="1.0" encoding="utf-8"?>
<resources  xmlns:android="http://schemas.android.com/apk/res/android">
    <color android:name="actionbar_title"></color>
</resources>

清除错误,但在布局文件中提供以下定义

clears the error but in a layout file the following definition

<TextView android:id="@+id/title"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textColor="@color/actionbar_title" />

出现错误错误:错误:找不到与给定名称匹配的资源(在'textColor'处,值为'@ color/actionbar_title').

gives the error "error: Error: No resource found that matches the given name (at 'textColor' with value '@color/actionbar_title').

任何人和所有帮助将不胜感激.

Any and all help will be appreciated.

正如type-a1pha所指出的,上面没有指定颜色-我是从测试版本复制过来的.但是

As pointed out by type-a1pha, the above did not specify a color - I've copied from a test version. However

<?xml version="1.0" encoding="utf-8"?>
<resources  xmlns:android="http://schemas.android.com/apk/res/android">
    <color android:name="actionbar_title">#ffffff</color>
</resources>

给出棉绒警告

Unexpected text found in layout file: "#ffffff"

但是在布局xml文件中仍然无法识别颜色资源.

but the color resource is still not recognised in the layout xml file.

推荐答案

您需要实际定义颜色:

<color name="white">#FFFFFF</color>

即给出其十六进制代码.

that is, give its hexadecimal code.

这篇关于颜色资源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆