Reputation: 6866
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
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
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.
Upvotes: 9
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