我想在我的一个项目中改变RadioButton的圆圈的颜色,但我不知道该设置哪个属性。背景颜色是黑色的,所以它是看不见的。我想把圆圈的颜色设置为白色。


当前回答

<android.support.v7.widget.AppCompatRadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:buttonTint="@color/Color" />

其他回答

使用app:buttonTint而不是android:buttonTint,像这样:

 <com.google.android.material.radiobutton.MaterialRadioButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="English"
        android:checked="true"
        app:buttonTint="#FF0000"
        android:textAppearance="@style/TextAppearance.Material3.TitleSmall"
        android:layout_marginHorizontal="16dp"
        android:layoutDirection="rtl"
        />

or

<RadioButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="English"
    android:checked="true"
    app:buttonTint="#FF0000"
    android:textAppearance="@style/TextAppearance.Material3.TitleSmall"
    android:layout_marginHorizontal="16dp"
    android:layoutDirection="rtl"
    />
<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radio"
    android:buttonTint="@color/my_color"/>

所有按钮都会改变颜色,包括圆形框和中央复选框。

创建一个可绘制文件my_compound_button_color_selector.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/text_app_color"/>
<item android:state_checked="true" android:color="@color/text_app_color"/>
<item android:color="@color/gray"/> </selector>

在style.xml文件中添加样式

<style name="AppRadioAppStyle" parent="Widget.AppCompat.CompoundButton.RadioButton">
    <item name="android:textColor">@drawable/my_compound_button_color_selector</item>
    <item name="drawableTint">@drawable/my_compound_button_color_selector</item>
</style>

布局文件

<RadioButton
                    android:id="@+id/radio1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:button="@null"
                    android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
                    android:gravity="center_horizontal|bottom"
                    android:background="@drawable/app_border_0"
                    android:padding="@dimen/_15sdp"
                    android:text="@string/no"
                    android:fontFamily="@font/poppins_medium"
                    style="@style/AppRadioAppStyle"
                    android:layout_marginStart="@dimen/_10sdp"/>

应该添加android:button="@null"在你的单选按钮

设置buttonTint属性。例如,android:buttonTint="#99FF33"。

要以编程方式更改单选按钮的颜色,您可以使用以下方法:

yourradio button name.buttonDrawable?.setColorFilter(Color.parseColor( color_value), PorterDuff.Mode.SRC_ATOP)