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)
Here is the checked state
Here is what I'm trying to make it look like.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With