android radiogroup样式(设置切换背景与文字颜色)
main.xml
1 <RadioGroup 2 android:id="@+id/radioGroup1" 3 android:layout_width="wrap_content" 4 android:layout_height="36dp" 5 android:layout_gravity="center" 6 android:layout_weight="1" 7 android:orientation="horizontal" > 8 9 <RadioButton 10 android:id="@+id/radio0" 11 android:layout_width="0dp"//设0才可以与radio1平分宽度 12 android:layout_height="wrap_content" 13 android:layout_weight="1" 14 android:background="@drawable/radio_check" 15 android:button="@null" 16 android:checked="true" 17 android:gravity="center" 18 android:text="@string/title" 19 android:textColor="@drawable/radio_text_check" /> 20 21 <RadioButton 22 android:id="@+id/radio1" 23 android:layout_width="0dp" 24 android:layout_height="wrap_content" 25 android:layout_weight="1" 26 android:background="@drawable/radio_check" 27 android:button="@null" 28 android:gravity="center" 29 android:text="@string/title2" 30 android:textColor="@drawable/radio_text_check" /> 31 32 </RadioGroup>
radio_text_check.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <selector xmlns:android="http://schemas.android.com/apk/res/android"> 3 4 <item android:state_checked="true" android:color="@android:color/white"/> 5 <item android:state_checked="false" android:color="@android:color/holo_blue_bright"/> 6 7 </selector>
radio_check.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image1" android:state_checked="true"/> <item android:drawable="@drawable/image2" android:state_checked="false"/> </selector>