I'm trying to add to my existing statelist drawable, a disabled state and it just doesn't work.
originally, I had this code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/store_item_background_selected" android:state_selected="true"/>
<item android:drawable="@drawable/store_item_background"/>
</selector>
and it worked perfectly for selected and not selected.
now I wanted to add the android:state_enabled="false" like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/store_item_background_selected" android:state_selected="true"/>
<item android:drawable="@drawable/store_item_background" android:state_enabled="true"/>
<item android:drawable="@drawable/store_item_background_disabled"/>
</selector>
and it never switches to the disabled image.
any ideas?
EDIT
I added setEnabled(false)
to the constructor of the view I'm setting this statelist drwable and now I see the disabled image, but once I set the view to enabled, it won't switch to disabled again.
Although this is a really old question, one should write a selector in this order:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:drawable="@color/due_gray" android:state_enabled="false" />
<item android:drawable="@color/whizdm_primary_dark_color" android:state_pressed="true" />
<item android:drawable="@color/whizdm_primary_color" />
</selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With