错误:应定义'color'属性

时间:2016-09-01 19:12:33

标签: android-selector

颜色选择器定义如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true">
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="@color/gray" />

        </shape>
    </item>
    <item android:state_focused="true">
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#66666666" />

        </shape>
    </item>
    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="@color/translucent_icon_background" />
        </shape>
    </item>
</selector>

在Android Studio中,“item”标记为红色,表示错误,如以下屏幕截图所示: enter image description here

该应用程序适用于每个测试。我问,因为我担心由于这个错误,它可能在某些设备上没问题。任何人都可以对这个错误有所了解吗?更具体地说,可以忽略吗?

1 个答案:

答案 0 :(得分:2)

我遇到了同样的错误,我通过添加带有商品标签的颜色属性来删除它。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffffff">  <--**add this** 
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <solid android:color="@color/gray" />

    </shape>
</item>
<item android:state_focused="true" android:color="#ffffff"> **<--add this** 
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <solid android:color="#66666666" />

    </shape>
</item>
<item android:color="#ffffff">   **<--add this** 
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <solid android:color="@color/translucent_icon_background" />
    </shape>
</item>

祝你好运。