Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change icons of checked and unchecked for Checkbox for Android

Instead of having a check mark for the icon, I want a custom star (I have checked and unchecked icons). Can this be done through a property? Or must I declare a custom widget that derives from Checkbox?

like image 728
Mohit Deshpande Avatar asked Jul 07 '10 05:07

Mohit Deshpande


1 Answers

Kind of a mix:

Set it in your layout file :-

 <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 the @drawable/checkbox will look like:

<?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> 
like image 183
ggomeze Avatar answered Oct 05 '22 08:10

ggomeze