android radiogroup样式(设置切换背景与文字颜色)

时间:2022-04-14 09:36:26

android radiogroup样式(设置切换背景与文字颜色)

main.xml

 <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" > <RadioButton
android:id="@+id/radio0"
android:layout_width="0dp"//设0才可以与radio1平分宽度
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/radio_check"
android:button="@null"
android:checked="true"
android:gravity="center"
android:text="@string/title"
android:textColor="@drawable/radio_text_check" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/radio_check"
android:button="@null"
android:gravity="center"
android:text="@string/title2"
android:textColor="@drawable/radio_text_check" /> </RadioGroup>
radio_text_check.xml
 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@android:color/white"/>
<item android:state_checked="false" android:color="@android:color/holo_blue_bright"/> </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>