android:state_pressed label failure or android:state_enabled label failure problem solving

Problem Description:

The android:state_pressed label is invalid or the android:state_enabled label is invalid, the click will not change color, and it will not change color when it is available/unavailable.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/purple_200"/>
    <item android:drawable="@color/lawn_green" android:state_enabled="false"/>
    <item android:drawable="@color/dark_gray" android:state_pressed="true"/>
</selector>

Solution:

Change the order of the three <item> tags to:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/dark_gray" android:state_pressed="true"/>
    <item android:drawable="@color/lawn_green" android:state_enabled="false"/>
    <item android:drawable="@color/purple_200"/>
</selector>

problem solved!

 Thoughts: outrageous! It's outrageous! TAT

Guess you like

Origin blog.csdn.net/LYly_B/article/details/129828879