12

I'm working on an android form with a radio group containing a set of radio buttons. From what I can tell there is no way to set the color a radio button highlights when you select it. It seems to always default to some bright green color. Is this something that is editable or no?

Thanks

Ryan
  • 6,756
  • 13
  • 49
  • 68
  • I think it's a litle bit late to give you an ansewr, but you can check my ansewr to this question: http://stackoverflow.com/a/35610511/1663453 – Sierisimo Feb 24 '16 at 18:49

3 Answers3

9

Yes you can create your own drawable for what you want it to look like when checked and use android:button to set it to the resource.

Example here

Community
  • 1
  • 1
Robby Pond
  • 73,164
  • 16
  • 126
  • 119
1

Use AppCompatRadioButton instead of RadioButton.

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

To change the color programatically do this:

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);
Rana Ranvijay Singh
  • 6,055
  • 3
  • 38
  • 54
0

On api level 21+ you can change the buttonTint

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myId"
android:checked="true"
android:buttonTint="@color/accent"/>
kingston
  • 11,053
  • 14
  • 62
  • 116