Can't change Radio Button color on Android

后端 未结 8 1601
忘了有多久
忘了有多久 2021-01-01 23:52

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

相关标签:
8条回答
  • 2021-01-02 00:08

    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>
      
    0 讨论(0)
  • 2021-01-02 00:09

    If you want to change the color, but not change colorControlActivated and colorControlNormal for the entire app, you can override your apptheme just for the radio button by creating a new style:

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentEnd="true"
        android:theme="@style/RadioButtonTheme"
        android:id="@+id/radioButton"/>
    
    
    
    <style name="RadioButtonTheme" parent="@style/AppTheme">
        <item name="colorControlActivated">@color/colorAccent</item>
        <item name="colorControlNormal">@color/colorPrimaryDark</item>
    </style>
    
    0 讨论(0)
提交回复
热议问题