android-selector - 错误 : 'color' attribute should be defined

标签 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
该应用程序在每个测试中都能正常工作。我问是因为我担心由于该错误,它在某些设备上可能不好。任何人都可以对这个错误有所了解吗?更具体地说,它可以被忽略吗?

最佳答案

我有同样的错误,我通过添加带有项目标签的颜色属性来删除它。

<?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>

祝你好运。

关于android-selector - 错误 : 'color' attribute should be defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39279222/

相关文章:

Android如何在按下或聚焦时使按钮文本变粗

Android 选择器在 tabhost 中不起作用

android - ?安卓 :attr/selectableItemBackground with another existing background

java - 仅更改 ImageButton 背景的一种状态(默认状态)

android - ListView 多选 - 默认透明颜色不能正常工作?

android - 使用选择器使按钮背景透明

android - 如何实现类似Google Play Music的抽屉导航选择器

android - 在可绘制选择器中更改实体的颜色