有没有什么方法可以改变单选按钮的颜色?

时间:2010-04-26 18:40:56

标签: android radio-button android-layout

我正在使用包含一组单选按钮的广播组的Android表单。据我所知,当您选择它时,无法设置单选按钮突出显示的颜色。它似乎总是默认为一些亮绿色。这是可编辑的还是没有?

由于

3 个答案:

答案 0 :(得分:9)

是的,您可以创建自己的drawable,以便在检查时看起来像它,并使用android:按钮将其设置为资源。

Example here

答案 1 :(得分:1)

使用 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"/>

要以编程方式更改颜色,请执行以下操作:

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);

答案 2 :(得分:0)

在api level 21+上你可以改变buttonTint

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