Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" />
like image 409
Isaac Perez Avatar asked Oct 08 '18 20:10

Isaac Perez


1 Answers

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

like image 136
lasagnakid77 Avatar answered Nov 04 '22 17:11

lasagnakid77