18

It has to be like this:

enter image description here

Currently it looks like this:

enter image description here

The rounded rectangle is not that important. But the unchecked state has to be black. This is my code:

<CheckBox
    android:id="@+id/checkbox"
    android:buttonTint="@color/orange"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

This is the theme I'm using:

  "Theme.AppCompat.Light.NoActionBar"

I've tried this as well:

<style name="checkbox_style" parent="Bijenkorf">
    <item name="material_grey_600">@color/black</item>
</style>

Because the default unchecked has the color #757575. And I looked this up in the Theme and it was "material_grey_600". But this doesn't compile. Any ideas?

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94
  • you can follow one of my answer on here. u require 3 xml, one for custom checkbox, 1 for when check box is checked and 1 for when checkbox is unchecked, here you define your color for black. http://stackoverflow.com/a/42764334/4056108 – chirag90 May 12 '17 at 09:20
  • @Jim Clermonts try [this](http://stackoverflow.com/a/40016892/3117966) – Nisarg May 12 '17 at 09:28
  • Follow the link http://stackoverflow.com/questions/5854047/how-to-change-the-color-of-a-checkbox – Ankita May 12 '17 at 09:31

3 Answers3

31

Do it like this-

In your layout file-

<android.support.v7.widget.AppCompatCheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:theme="@style/CheckboxStyle"/>

and in your style.xml file

<style name="CheckboxStyle" parent="AppTheme">
    <item name="colorAccent">@color/colorAccent</item>
</style>

Or you can change both the checked and unchecked color like this-

<style name="CheckboxStyle" parent="AppTheme">
    <item name="colorAccent">@color/colorAccent</item>  // for checked 
    <item name="android:textColorSecondary">@color/colorSecondary</item>  // for unchecked
</style>

change colorAccent and colorSecondary with your required colors.

hope it will help you..

D_Alpha
  • 4,039
  • 22
  • 36
20

I know it is answered but someone may find this useful, another way to achieve this is by using color state list, declare a color state list for the checkbox in an xml file

checkbox_state_list.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:color="@color/orange" android:state_checked="true"/>
   <item android:color="@color/black" android:state_checked="false"/>
</selector>

Now use this state list as

<android.support.v7.widget.AppCompatCheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:buttonTint="@color/checkbox_state_list"/>
RamIndani
  • 678
  • 8
  • 12
2

You have to use CheckBox style like this:

in xml style

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

in xml layout .

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    style="@style/MyCheckBox"
    ...