Error: 'color' attribute should be defined
Error: 'color' attribute should be defined
颜色选择器定义如下:
<?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”标记为红色,表示出现错误,如下面的屏幕截图所示:
该应用程序在每次测试中都运行良好。我问是因为我担心由于该错误在某些设备上可能无法正常工作。谁能阐明这个错误?更具体地说,可以忽略吗?
我有同样的错误,我通过在项目标签中添加颜色属性来删除它。
<?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>
祝你好运。
您需要在 'drawable/' 文件夹而不是 'color/' 文件夹中创建 'selector.xml'。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">
<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”标记为红色,表示出现错误,如下面的屏幕截图所示:
该应用程序在每次测试中都运行良好。我问是因为我担心由于该错误在某些设备上可能无法正常工作。谁能阐明这个错误?更具体地说,可以忽略吗?
我有同样的错误,我通过在项目标签中添加颜色属性来删除它。
<?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>
祝你好运。
您需要在 'drawable/' 文件夹而不是 'color/' 文件夹中创建 'selector.xml'。enter image description here