Search code examples
androidandroid-stylesandroid-checkbox

Disabled checkbox color


I have a button that enables/disables a checkbox but I cannot see the disabled checkbox due to the color it turns (my style background color must be the same color as the disabled checkbox). How do I change the color of a disabled checkbox and also ensure that the color returns to an "enabled" color when the checkbox becomes enabled again?

This is what I mean:

enter image description here

The checkbox in question is simple:

   <CheckBox
       android:id="@+id/settings_hide_nsfw_thumbnails"
       android:layout_width="wrap_content"
       android:layout_height="match_parent" />

Solution

  • Easiest to define a new style and apply it to the checkbox in xml.

    <style name="MyCheckBox" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">@color/notactive</item>
        <item name="colorControlActivated">@color/active</item>
    </style>
    

    apply it with android:theme="@style/MyCheckBox"

    normal= not selected