我想通过创建一个单选按钮创建一个可选择的选中和未选中状态的自定义按钮。但是没有显示任何内容来代替按钮。
我的代码:
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@+id/imageView10"
app:layout_constraintTop_toBottomOf="@+id/titleTextView"
android:layout_margin="15dp">
<RadioButton
style="@style/TitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="email"
android:textSize="22sp"
android:textIsSelectable="true"
android:button="@drawable/radio_button_selectable"/>
<RadioButton
style="@style/TitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="anonymous"
android:textSize="22sp"
android:textIsSelectable="true"
android:checked="true"
android:button="@drawable/radio_button_selectable"/>
</RadioGroup>
radio_button_selectable.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/radio_button_selected"/>
<item android:state_checked="false" android:drawable="@drawable/radio_button_unselected"/>
</selector>
radio_button_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#FFF95B"
android:startColor="#FF930F" />
<stroke
android:width="2dp"
android:color="@color/white" />
</shape>
radio_button_unselected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/darker_gray" />
<stroke
android:width="2dp"
android:color="@color/white" />
</shape>
它看起来如何:
Screenshot of radio button
1条答案
按热度按时间s4n0splo1#
更改此代码:
Android:background="@drawable/radio_button_selectable”Android:button="@null”/