我尝试创建自定义单选按钮但效果不佳,使用以下代码: custom_radio.xml
<?xml version="1.0" encoding="utf-8"?>
<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_on" android:state_pressed="true"/>
<item android:drawable="@drawable/radio_off"/>
</selector>
和main.xml
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="vertical" >
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/male"
android:background="@xml/custom_radio"
android:textColor="@color/white" />
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/female"
android:background="@xml/custom_radio"
android:textColor="@color/white" />
</RadioGroup>
结果如下:
如何解决这个问题?
答案 0 :(得分:1)
添加
android:button="@null"
到RadioButton
。像xml一样的drawable也应放在drawable
文件夹