Android: Set color of CheckBox

Solution 1:

You can use a custom check box xml file for this. Save the below xml code in drawables folder, name it custom_checkbox.xml:

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

Then use this file as background of your checkbox like this:

       <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/custom_checkbox"
        android:id="@+id/checkBox" />

Here I am uploading my own images which I used in place of cbchk_blue and cbunchk_blue

Unchecked CheckBoxChecked CheckBox

Solution 2:

Same problem also happens when you use theme Holo Dark for Activity and white background. So checkbox has Dark style. Simple workaround is directly set background from Android's Holo Light:

int id = Resources.getSystem().getIdentifier("btn_check_holo_light", "drawable", "android");
checkBox.setButtonDrawable(id);

You can find great overview how all this things work in following answer: https://stackoverflow.com/a/10139809/1170154