Android : Change RadioButton's Icon(circle) using selector - Doesn't work

on Monday, February 16, 2015


I am trying to change the RadioButton's circle drawable using selector. The selector is simple, when selected - show radio_on image and when not selected - show radio_off image. I don't want to handle other states.


Here is my selector: radio_button_background.xml



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

<item android:drawable="@drawable/radio_on" android:state_checked="true"/>
<item android:drawable="@drawable/radio_off" android:state_checked="false"/>

</selector>


The selector is applied to the RadioButton as follows:



<RadioButton
android:id="@+id/radio_no_of_days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:button="@drawable/radio_button_background"
android:text="@string/dt_text_days"
android:textSize="18sp" />


I can see that the selector is applied in design view, because the radio_off is getting set, but when i click on the RadioButton, the image is not changing to radio_on. What am i doing wrong?


0 comments:

Post a Comment