1. Create radio_button.xml in drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_radio_on" android:state_checked="true" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_radio_off" android:state_checked="false" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_radio_on_pressed" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_radio_off_pressed" android:state_checked="false" android:state_pressed="true"/>
</selector>
note: images used in radio_button.xml file.
2. Use radiogroup in any layout.
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/radioButton3"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView2" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Name"
android:button="@drawable/radio_button"
android:textColor="#000000" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:button="@drawable/radio_button"
android:layout_height="wrap_content"
android:text="Code"
android:textColor="#000000" />
</RadioGroup>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_radio_on" android:state_checked="true" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_radio_off" android:state_checked="false" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_radio_on_pressed" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_radio_off_pressed" android:state_checked="false" android:state_pressed="true"/>
</selector>
note: images used in radio_button.xml file.
2. Use radiogroup in any layout.
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/radioButton3"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView2" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Name"
android:button="@drawable/radio_button"
android:textColor="#000000" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:button="@drawable/radio_button"
android:layout_height="wrap_content"
android:text="Code"
android:textColor="#000000" />
</RadioGroup>
No comments:
Post a Comment