我的RadioGroup中的RadioButtons在我取消勾选或单击该组中的另一个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>
删除单选按钮的背景
android:background="?android:selectableItemBackground"
并使用android:button="@drawable/radiobutton_selector"
下面是一个Android中自定义单选按钮的例子,请大家看一下,也许对你有帮助。http:/www.apnatutorials.comandroidandroid-radiobutton-customization-and-usage.php?categoryId=2&subCategoryId=62&myPath=androidandroid-radiobutton-customization-and-usage.php。
使用 MaterialRadioButton
的支持库(com.google.android.material)。这个问题可能是由于 RadioButton
取决于API版本与主题和选择器的结合。使用 MaterialRadioButton
将统一各API版本的行为。
这里 是这个组件的一个小付出。
'com.google.android.material:material:1.0.0'
依赖关系应该被导入到项目中,并且是应用中使用的Material主题之一。
希望能帮到你。
你必须使用buttonTint来实现这个功能,你的radioButton应该是这样的。
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:buttonTint="@color/your_color"/>
你的radioButton应该是这样的。然而这在API 21之前是行不通的这里有一个针对API 21之前的设备的解决方案。改变单选按钮的圆圈颜色