2

I have been coding an Android Application, and using CheckBox for GUI.

Generally, the style of CheckBox is a green colored tick, but I want to make it red colored cross.

How to do it.? Please Help.

Veer Shrivastav
  • 5,434
  • 11
  • 53
  • 83
  • I want to change the style.. not the color. Changing color is just a part of question. main part is how to change the the `tick` to `X` – Veer Shrivastav Mar 14 '13 at 17:20

4 Answers4

2

Take a Custom Drawable selector with one image for unchecked state and another for checked state and set it as drawable resource for your Checkbox

Example:

Create a xml file in res/drawable folder

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_checked="true" android:drawable="@drawable/crossimagecheckbox" />
    <item android:state_checked="false" android:drawable="@drawable/uncheckecheckbox" />

</selector>
Pragnani
  • 20,075
  • 6
  • 49
  • 74
2

You can set any color of tick mark of Checkbox. but you need to make the custom checkbox for that.

Look here and here.

Source : Android: Set color of CheckBox

<?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">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@color/blue_dark" />
        <gradient  android:endColor="@color/white" android:startColor="@color/blue_dark" android:type="sweep"  />
        <size android:height="30dp" android:width="30dp" />
    </shape>
</item>
<item android:state_checked="true" 
    android:drawable="@drawable/cbchk_blue"
    android:state_focused="true">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@color/white" />
        <gradient  android:endColor="@color/white" android:startColor="@color/blue_dark" android:type="sweep"  />
        <size android:height="30dp" android:width="30dp" />
    </shape>
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/cbunchk_blue"
    android:state_focused="false">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@color/blue_dark" />
        <size android:height="30dp" android:width="30dp" />
    </shape>
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/cbunchk_blue"
    android:state_focused="true">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@color/white" />
        <size android:height="30dp" android:width="30dp" />
    </shape>
</item>
Community
  • 1
  • 1
Ajay S
  • 48,003
  • 27
  • 91
  • 111
2

You need to create a selector for checkbox.

in layout checkbox add the following:

android:background="@drawable/checkbox_selector"

in checkbox_selector.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false"
        android:drawable="@drawable/normal_picture" />
    <item android:state_checked="true"
        android:drawable="@drawable/checked_picture" />
</selector>

Now create normal_picture and checked_picture according to your requirement.

Barney
  • 2,355
  • 3
  • 22
  • 37
stinepike
  • 54,068
  • 14
  • 92
  • 112
1

I believe this link is highly relevant. Read Jean's answer:

Checkboxes being children of Button you can just give your checkbox a background image with several states as described here, under "Button style": http://developer.android.com/reference/android/widget/Button.html

...and exemplified here: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Community
  • 1
  • 1
Barney
  • 2,355
  • 3
  • 22
  • 37