Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Set color of CheckBox

I've searched a number of places and don't seem to be able to figure out the CheckBox drawable for the border of the check box. Can anyone point me in the correct direction?

Here is what it looks like unchecked (Can barely see the box)

enter image description here

Here is the checked state

enter image description here

Here is what I'm trying to make it look like.

enter image description here

like image 622
Kirk Avatar asked Jul 13 '12 04:07

Kirk


People also ask

How to change checkbox checked color 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 to make checkbox color android?

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 to set checkbox color?

To style the checkbox the user first needs to hide the default checkbox which can be done by setting the value of the visibility property to hidden. Example 1: Consider the example where HTML checkbox is styled using CSS. When the user clicks the checkbox, the background color is set to green.

How can I change the color of bootstrap checkbox?

input[type=checkbox] does not not have a background-color property. You can use other ways to get your desirable result: You can use the checkbox inside a div and then style the div according to your needs.


1 Answers

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

like image 164
Ram kiran Pachigolla Avatar answered Sep 25 '22 16:09

Ram kiran Pachigolla