2

I am using checkbox as below

checkbox img

My code...

   <CheckBox
    android:id="@+id/checkBox10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="32dp"
    android:layout_weight="1"
    android:button="@null"
    android:checked="true"
    android:drawableBottom="?android:attr/listChoiceIndicatorMultiple"
    android:gravity="center_horizontal"
    android:text="10"
    android:textColor="#FFFFFF"
    android:textStyle="bold"
    android:theme="@style/MyCheckBox"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

style.xml

 <style name="MyCheckBox" parent="Theme.AppCompat.Light">
    <item name="colorControlNormal">#ffffff</item>
    <item name="colorControlActivated">#ff0000</item>       
 </style>

I can change the box color by changing the color in style xml.As i am using

 android:button="@null"
 android:drawableBottom="?android:attr/listChoiceIndicatorMultiple" 

I couldnt find a way to change the tick color. I need to change the tick color (which is blue) coming as the background color. How can i do that.?

sony
  • 77
  • 1
  • 12
  • Does this answer your question? [How to change check box tick color in android](https://stackoverflow.com/questions/20542693/how-to-change-check-box-tick-color-in-android) – karan Apr 13 '20 at 09:09
  • No.. i am using a diffrent code to align my checkbox and text vertically. so cant use that method – sony Apr 13 '20 at 09:47

2 Answers2

3

Create a selector XML file in res\drawables\ folder with name cb_selector.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/checked" />
    <item android:state_checked="false" android:drawable="@drawable/unchecked" />
</selector>

In your layout file apply this file to your checkBox

<CheckBox
    android:id="@+id/cb"
    android:text="My CheckBox"
    android:button="@drawable/cb_selector"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

Add a unchecked.png, and checked.png in your drawable folder. These are checked and unchecked image of a checkbox.

You can use color instead of drawable also

Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
0

I achieved this by using AppCompatCheckBox with app:buttonCompat="@drawable/your_selector_drawable".

Dharman
  • 30,962
  • 25
  • 85
  • 135
Andrain
  • 872
  • 1
  • 16
  • 43