颜色选择器定义如下:
<?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>
祝你好运。
关于android-selector - 错误 : 'color' attribute should be defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39279222/