颜色选择器定义如下:
<?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>
Run Code Online (Sandbox Code Playgroud)
在 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>
Run Code Online (Sandbox Code Playgroud)
祝你好运。