Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the check box (tick box) color to white in android XML

Tags:

Is there any way to change the check box (tick box) color to white in android XML. (I need white color tick box which contain black tick, as the preview I got in android studio inside my real device)

Here is my code for check box

<CheckBox
    android:textSize="15sp"
    android:textColor="#fff"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save Loging "
    android:id="@+id/checkBox"
    android:layout_below="@id/PasswordeditText"
    android:checked="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:buttonTint="#fff" />

When I add android:buttonTint="#fff" preview show the change I need, but it doesn't work in real device

Design preview

enter image description here

Real Device

enter image description here

Is there any attribute like android:buttonTint which I can use to achieve the changes in real device.

like image 778
Nadeesha Thilakarathne Avatar asked Aug 05 '15 18:08

Nadeesha Thilakarathne


People also ask

How do I change the color of a checkbox box?

If you want to change checkbox color then "colorAccent" attribute will use for checked state and "android:textColorSecondary" will use for unchecking state. "actionOverflowButtonStyle" will use for change the color of overflow icon in the Action bar. Same is for refresh button which i am using in my app.

How can change fill color of checkbox in android?

This example demonstrates how do I change the color of the check box in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How can I change checkbox color checked?

Demonstrating checkbox checked red background color using CSS. Use the accent-color property to change the checkbox color in CSS.

How do I create a check box in XML?

To define the click event handler for a checkbox, add the android:onClick attribute to the <CheckBox> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.


2 Answers

Set the colorAccent to your desired color:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorAccent">#fff</item>
</style>

Or if you don't want to change your main theme, create a new theme and apply it only to the checkbox:

<style name="WhiteCheck">
    <item name="colorAccent">#fff</item>
</style>

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/WhiteCheck"/>
like image 80
tachyonflux Avatar answered Sep 21 '22 02:09

tachyonflux


This is variation of tachyonflux's answer:

Try to change buttonTint:

<style name="my_checkbox_style">
    <item name="buttonTint">#fff</item>
</style>

<CheckBox
            android:id="@+id/my_checkbox"
            style="@style/my_checkbox_style"
            android:background="#000" />
like image 23
Dragan Stojanov Avatar answered Sep 19 '22 02:09

Dragan Stojanov