mardi 19 avril 2016

Custom button drawable state_pressed and state_checked not working on CheckBox or RadioButton - Android

I am setting custom drawable to the checkbox button,
But only android:state_checked="true" and android:state_checked="false" seem to work.
Other states aren't working.

I am unable to set a custom drawable on pressed state.

This is the selector I am using:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
    <item android:state_checked="true" android:drawable="@drawable/radio_btn_selected" />
    <item android:state_checked="false" android:drawable="@drawable/radio_btn_normal" />
    <item android:state_pressed="true"  android:drawable="@drawable/radio_btn_pressed" />
    <item android:state_focused="true"  android:drawable="@drawable/radio_btn_pressed" />
    <item android:drawable="@drawable/radio_btn_normal"/> <!-- default -->
</selector>

This is how I am setting it to radio button:

radioButton.setButtonDrawable(R.drawable.radio_btn_selectors);




Aucun commentaire:

Enregistrer un commentaire