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.
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.
 
    
    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>
 
    
    You can set any color of tick mark of Checkbox. but you need to make the custom checkbox for that.
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>
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.
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