Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change check box tick color in android

I am developing android application In that i use check box but default check box tick color is blue so i want to change that color to yellow. is there any inbuilt property to set color to check box tick.

like image 221
Atul K Avatar asked Dec 12 '13 11:12

Atul K


People also ask

How to change the color of a checkbox in Android?

If your minSdkVersion is 21+ use android:buttonTint attribute to update the color of a checkbox: <CheckBox ... android:buttonTint="@color/tint_color" /> In projects that use AppCompat library and support Android versions below 21 you can use a compat version of the buttonTint attribute:

How to change checkbox checked icon color in flutter?

All Checkbox widgets has same mark icon present inside them which is a right tick mark icon. In flutter the Checkbox widget has a property named as checkColor which is used to Flutter Change Checkbox Checked Icon Color in Android iOS apps. The default color property is White color.

How do I create a checkbox as a theme in Android?

In short: create a style for the checkbox, e.g. checkboxStyle and then implement it as a theme: android:theme="@style/checkboxStyle" Firstly, we must create a drawable that include checked and uncheck color situations, then you must set this drawable as buttonTint;

What is the use of custom checkbox in Android?

Custom checkbox is required by thousands of android developer who wish to modify the checkbox functionality according to their customer requirement . So here is the complete step by step tutorial for Material Design Custom Checkbox using theme.


2 Answers

Unfortunately, changing the color of checkbox check mark isn't a simple attribute

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 drawables folder. These are checked and unchecked image of checkbox.

like image 101
Vaibhav Agarwal Avatar answered Oct 13 '22 16:10

Vaibhav Agarwal


You can use the attribute app:buttonTint of the AppCompatCheckBox from the android.support.v7 library.

<android.support.v7.widget.AppCompatCheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/colorAccent"/>

Advantage: works also below API 21 and you don't need to redraw the checkbox.

like image 22
dabo248 Avatar answered Oct 13 '22 14:10

dabo248