【发布时间】:2020-08-27 12:08:51
【问题描述】:
我的 RadioGroup 中的 RadioButton 在我取消选中它们或单击组中的另一个 RadioButton 后留下一个黑色的选中圆圈。如何防止这种情况发生?
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textAlignment="textStart"
android:layoutDirection="rtl"
android:layout_gravity="start"
android:background="?android:selectableItemBackground"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="textStart"
android:layoutDirection="rtl"
android:layout_gravity="start"
android:background="?android:selectableItemBackground"/>
</RadioGroup>
发生在我的 API 19 真实设备上,而不是我的 API 27
编辑:_________________________________________________
尝试使用不起作用的自定义选择器
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/qrmenu_toolbar"
android:orientation="vertical">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Resume"
android:layoutDirection="rtl"
android:layout_gravity="start"
android:drawablePadding="12dp"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="16dp"
android:paddingBottom="12dp"
app:drawableLeftCompat="@drawable/ic_resume"
android:button="@drawable/radiobutton_selector"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/radio_checked" android:state_checked="true" />
<item android:drawable="@drawable/radio_unchecked" android:state_checked="false" />
</selector>
主题:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorBlack</item>
<item name="colorPrimaryDark">@color/colorBlack</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
bump还是找不到解决办法
编辑:______________________________________
也尝试使用自定义单选按钮..仍然不起作用:
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/custom_radio_button"/>
自定义单选按钮:
<?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/ic_radio_button_checked"/>
<item android:state_checked="false" android:drawable="@drawable/ic_radiobutton_unchecked"/>
</selector>
【问题讨论】:
-
您是否尝试从 RadioButton 中删除 android:background 属性并对其进行测试?请提供设备型号。
-
是的,我删除了背景属性,它仍然有它。三星 Galaxy Note3。
-
我认为您可以尝试一些手动清除。通过 setOnCheckedChangeListener 将监听器添加到 RadioGroup 中,首先通过 clearCheck 清除当前检查,然后立即通过 check 方法设置检查项。
-
尝试为每个
RadioButton提供ID,例如android:id="@+id/one",android:id="@+id/two" -
检查这个:- 这将有助于stackoverflow.com/a/34513545/9523118
标签: android android-radiobutton android-radiogroup