Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change Radio Button color on Android

I'm using Android Studio. I need to change the color of the Radio Button, after changing the Button Tint Color value to the one I need it works on the preview, but whenever I launch the app on a device the button is the standard green/blue-ish color.

Is this some kind of device API level issue? If so, is it possible to change the color for older devices?

like image 947
Freguglia Avatar asked Feb 03 '15 19:02

Freguglia


People also ask

How can change radio button background color in Android?

Just use the android:buttonTint="@color/colorPrimary" attribute on the <RadioButton> tag. Show activity on this post. to the colour you want.

What is the default button color in Android?

Show activity on this post. When I open a new android studio project, the default color for button is purple.

What is radio button group in Android?

↳ android.widget.RadioGroup. This class is used to create a multiple-exclusion scope for a set of radio buttons. Checking one radio button that belongs to a radio group unchecks any previously checked radio button within the same group. Intially, all of the radio buttons are unchecked.


2 Answers

This can be done in two ways (to support pre-Lollipop):

  1. Use AppCompatRadioButton:

    AppCompatRadioButton radioButton;
    // now use following methods to set tint colour
    radioButton.setSupportButtonTintMode();
    radioButton.setSupportButtonTintList();
    
  2. Apply this as style to your RadioButton in your XML:

    <style name="RadioButton.Login" parent="Widget.AppCompat.CompoundButton.RadioButton">
        <item name="android:textColor">@android:color/white</item>
        <item name="buttonTint">@android:color/white</item>
    </style>
    
like image 190
Sufian Avatar answered Sep 20 '22 15:09

Sufian


RadioButton raPrivate = (RadioButton) layout.findViewById(R.id.radioPrivate);
int textColor = Color.parseColor(#000000);
raPrivate.setButtonTintList(ColorStateList.valueOf(textColor));
like image 21
BooNonMooN Avatar answered Sep 18 '22 15:09

BooNonMooN