Android 有没有办法改变单选按钮的颜色?

Android 有没有办法改变单选按钮的颜色?,android,radio-button,android-layout,Android,Radio Button,Android Layout,我正在开发一个android表单,其中包含一组单选按钮。据我所知,没有办法设置单选按钮在选择时高亮显示的颜色。它似乎总是默认为一些明亮的绿色。这是可编辑的还是不可编辑的 谢谢是的,您可以创建自己的drawable,使其在选中时看起来像您想要的样子,并使用android:按钮将其设置为资源 在api级别21+上,您可以更改按钮 <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_conten

我正在开发一个android表单,其中包含一组单选按钮。据我所知,没有办法设置单选按钮在选择时高亮显示的颜色。它似乎总是默认为一些明亮的绿色。这是可编辑的还是不可编辑的


谢谢

是的,您可以创建自己的drawable,使其在选中时看起来像您想要的样子,并使用android:按钮将其设置为资源


在api级别21+上,您可以更改按钮

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myId"
android:checked="true"
android:buttonTint="@color/accent"/>

使用AppCompatRadioButton代替RadioButton

  <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rb"
        app:buttonTint="@color/colorAccent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

我认为现在给你一个ansewr有点晚了,但是你可以检查我的ansewr来回答这个问题:在API小于21或使用兼容性时:
ColorStateList colorStateList = new ColorStateList(
                new int[][]{
                        new int[]{android.R.attr.state_enabled} //enabled
                },
                new int[] {getResources().getColor(R.color.colorPrimary) }
        );

AppCompatRadioButton radioButton = (AppCompatRadioButton) findViewById(R.id.rb);
radioButton.setSupportButtonTintList(colorStateList);