androidandroid-layoutandroid-drawableandroid-selector

state_enabled="false" doesn't work, but the anothers work


Hello I have the following code:

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_enabled="false"
        android:color="#FF0000"
        android:drawable="@drawable/white_button_disable"/>

    <item android:state_pressed="true"
        android:drawable="@drawable/white_button"/>

    <item
        android:drawable="@drawable/white_button_shadow"
        android:bottom="4px" />

</selector>

white_button_disable

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/red"/>
    <corners android:radius="28dp"/>
    <stroke
        android:width="1px"
        android:color="@color/red" />
</shape>

If the button is clicked it shows the white_button, if the buttons don't press it shows white_buttons_shadow.

But if the button is disabled (enabled = "false") it doesn't work, and shows white_button_shadow

Any idea?


Solution

  • Just tested it

     <item android:state_enabled="false"
         android:drawable="@drawable/white_button_disable"/>
    

    Your android:color="#FF0000" is breaking the selector.

    Remove it and you should be fine.