RadioButton can be combined with selector to change the background by android:state_checked value
The key code in the XML layout file:
<radiogroup
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentend= "true"
Android:layout_alignparentright= "true"
Android:layout_centervertical= "true"
Android:layout_marginend= "30DP"
android:layout_marginright= "30DP"
android:orientation= "Horizontal" >
<radiobutton
Android:id= "@+id/image_female"
Android:layout_width= "80DP"
android:layout_height= "40DP"
Android:layout_marginend= "2DP"
android:layout_marginright= "2DP"
android:button= "@null"
android:background= "@drawable/female_sytle"
android:contentdescription= "@string/image_female_description"/>
<radiobutton
Android:id= "@+id/image_male"
Android:layout_width= "80DP"
android:layout_height= "40DP"
android:button= "@null"
android:background= "@drawable/male_style"
android:contentdescription= "@string/image_male_description"/>
</RadioGroup>
Female_style.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_checked= "true" android:drawable= "@drawable/register_female_checked" ></item>
<item android:state_checked= "false" android:drawable= "@drawable/register_female" ></item>
<item android:drawable= "@drawable/register_female" ></item>
</selector>
Male_sytle.xml
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_checked=" true "android:drawable=" @drawable/register_male_checked "></ Item> <item android:state_checked= "false" android:drawable= "@drawable/register_male" ></item> <it Em android:drawable= "@drawable/register_male" ></item>
</selector>
Reference: Http://www.eoeandroid.com/forum.php?mod=viewthread&tid=319623&extra=page%3D1&page=1
The first one answers
:
Android button to change background after pressing