vendredi 11 octobre 2019

custom checkbox with enable disable and selected in android

This is my simple selector

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_square_blue_border_unselected" android:state_checked="false" />
    <item android:drawable="@drawable/ic_square_checkbox_selected" android:state_checked="true" />
    <item android:drawable="@drawable/ic_square_blue_border_unselected" />
</selector>

When i add state_enabled : false/true it says,
"This item is unreachable as the previous item is more general match"
...i donot understand why it is so? since i am also adding a new property -> state_enabled...i was thinking it will be like if both properties are matched then only select the respective drawable.

I want to do something like,

checked && not disabled -> blue color checked box,
not checked && not disabled -> blue border unchecked box,
checked && disabled -> gray color checked box,
not checked &&  disabled -> gray color unchecked box

And, checkbox.setEnabled(false) is not working for this case. This is my xml code.

<CheckBox
                        android:id="@+id/checkbox"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:button="@drawable/selector_chkbox_blue_border"
                        android:textColor="@color/steel_grey"
                        android:paddingLeft="10dp"
                        android:text="Checkbox text"/>



Aucun commentaire:

Enregistrer un commentaire