【发布时间】:2017-10-12 23:08:13
【问题描述】:
我尝试更改 RadioButton 上选中按钮的可绘制对象,但没有显示任何内容;设置drawable只会删除已经存在的默认值。
我使用堆栈溢出来尝试找到解决方案,但是当我尝试实现它时,没有显示可绘制对象。我的选择器似乎很好,因为当我设置显示我的圈子的单选按钮的 background 时。
我确信这是一个非常明显的问题,我会因为没有看到而扇耳光;谁能找出问题所在?
我的单选按钮
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:checked="false"
android:button="@drawable/radio_button" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/radio_button"
android:text="Right"
android:checked="true" />
</RadioGroup>
使用我的选择器
没有我的选择器
我的选择器 XML
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/radio_button_checked"
android:state_checked="true" />
<item
android:drawable="@drawable/radio_button_unchecked" />
</selector>
radio_button_checked.xml
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/primary_button_color"/>
<stroke
android:width="2px"
android:color="#000000"/>
</shape>
radio_button_unchecked.xml
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2px"
android:color="#000000"/>
</shape>
【问题讨论】:
标签: android radio-button android-drawable