Reputation: 573
I have created a drawable selector xml file that my checkboxes reference. The ON and OFF selections work fine, but the disabled selector does nothing when I programmatically disable the view. What is the correct way to set the image for the disabled state within the xml selector?
XML File:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checkbox_on" android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_off" android:state_checked="false"/>
<item android:drawable="@drawable/checkbox_disabled" android:state_enabled="false"/>
</selector>
Java Code:
CheckboxAppDaily.setEnabled(false);
Upvotes: 3
Views: 1462
Reputation: 11
Maybe you can follow my coding, you should take 2 parameters to meet you requirement.
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/pay_bg_rectangle_selected" /> <item android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/pay_bg_rectangle_unselected" /> <item android:state_enabled="false" android:state_checkable="false" android:drawable="@drawable/pay_bg_rectangle_disable" /> </selector>
Upvotes: 1