Skip to content

Instantly share code, notes, and snippets.

@redleafar
Created September 14, 2016 19:45
Show Gist options
  • Save redleafar/782bd0c2ae846753d14f193c328c1bdb to your computer and use it in GitHub Desktop.
Save redleafar/782bd0c2ae846753d14f193c328c1bdb to your computer and use it in GitHub Desktop.
Change icons checkbox depending of its states

In the layout:

<CheckBox android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="new checkbox"
 android:background="@drawable/checkbox_background" 
 android:button="@drawable/checkbox" />

Where @drawable/checkbox is:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" android:state_focused="true"
  android:drawable="@drawable/checkbox_on_background_focus_yellow" />
 <item android:state_checked="false" android:state_focused="true"
  android:drawable="@drawable/checkbox_off_background_focus_yellow" />
 <item android:state_checked="false"
  android:drawable="@drawable/checkbox_off_background" />
 <item android:state_checked="true"
  android:drawable="@drawable/checkbox_on_background" />
</selector>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment