4

I want to change the colour of Square box of checkbox, not the colour of text, only that square image in which we tick.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
AMIT
  • 390
  • 1
  • 4
  • 17

4 Answers4

9

You can color directly in the xml. Use buttonTint for the checkbox

 <CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox"
    android:buttonTint="@color/lightColoral"
    />

The below code works on API < 21

app:buttonTint="@color/lightColoral"
NSetty
  • 140
  • 11
2

You can use AppCompat Checkbox and use app:buttonTint="@color/yellow".

            <android.support.v7.widget.AppCompatCheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="CheckBox"
                app:buttonTint="@color/yellow"
                />
Hari
  • 490
  • 1
  • 4
  • 12
0

You can provide custom theme for the checkbox

<style name="CheckBoxTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">@color/yourColor</item>
</style>
Deepak Goyal
  • 4,747
  • 2
  • 21
  • 46
0

Add this to your theme

<style name="CheckBoxTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:textColorSecondary">@color/blue</item>
    <item name="colorAccent">@color/blue</item>
    <item name="colorControlNormal">@color/blue</item>
</style>

then in xml write next :

<android.support.v7.widget.AppCompatCheckBox
    android:theme="@style/CheckBoxTheme"/>

For API 21+ should be use:

<android.support.v7.widget.AppCompatCheckBox
    android:buttonTint="@color/blue"/>
Vladimir Eremeev
  • 262
  • 1
  • 10