12

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

谢谢

4

3 回答 3

9

是的,您可以创建自己的可绘制对象,使其在选中时看起来像您想要的样子,并使用 android:button 将其设置为资源。

这里的例子

于 2010-04-26T19:02:08.707 回答
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);
于 2016-07-25T10:54:27.710 回答
0

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

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myId"
android:checked="true"
android:buttonTint="@color/accent"/>
于 2015-10-16T14:50:51.527 回答