Ryan
Ryan

Reputation: 6866

Any way to change the color of a radio button?

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

Upvotes: 12

Views: 18114

Answers (3)

Rana Ranvijay Singh
Rana Ranvijay Singh

Reputation: 6165

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

Upvotes: 1

Robby Pond
Robby Pond

Reputation: 73494

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

Upvotes: 9

kingston
kingston

Reputation: 11419

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

Upvotes: 0

Related Questions