I need to have custom checkboxes which wasn’t that tricky. I made checkbox_selector to drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/checkbox_disabled" /><!-- disabled -->
<item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/checkbox_unchecked_focused" /><!-- pressing unchecked box -->
<item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/checkbox_checked_focused" /><!-- pressing checked box -->
<item android:state_checked="true" android:drawable="@drawable/checkbox_checked" /><!-- checked box -->
<item android:state_checked="false" android:drawable="@drawable/checkbox_unchecked" /><!-- unchecked box -->
</selector>
But the problem is that every checkbutton I make, I’ve to add
<Checkbox
android:button="@drawable/checkbox_selector" />
Trying to google answer for a some time and maybe I just can’t find the right words.
Can I say somewhere that every checkbox in this application should use this @drawable/checkbox_selector?
EDITED:
Saying in styles.xml
<style name="customCheckBox">
<item android:button>@drawable/checkbox_selector</item>
</style>
Worked for me in Android 2.3.3
But when I tried with Android 4.0.3 it doesn’t work. Any Idea why is that?
you can use style for this purpose:
Just set in your style.xml this:
And then just apply your theme to all your Checkbox, doing this:
For more reference about styles just read:
http://developer.android.com/guide/topics/ui/themes.html