Reputation: 1638
I have an android application. There is an activity which demands 7 checkboxes but as the size of the default check boxes provided by SDK is very large and takes lots of space, I tried to develop my own customized check boxes.
For this, I have captured two images (checked and unchecked), On click of one it toggles, i.e. on click of checked it converts to unchecked and vice versa.
But I want to know is there any other way to do this..
Upvotes: 2
Views: 2952
Reputation: 3313
It's little simple by placing an appropriate drawable xml file for your checkbox states with corresponding images you need to set.
place the below code in drawable named checkbox.xml
<?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/star_checked" /> <!-- pressed -->
<item android:state_checked="false"
android:drawable="@drawable/star_unchecked" /> <!-- focused -->
<item android:drawable="@drawable/star_unchecked" />
</selector>
and on your checkbox set above code to manipulate, by using android:button=@drawable/checkbox"
<CheckBox android:id="@+id/chkFav" android:layout_width="wrap_content"
android:layout_marginRight="0dp" android:button="@drawable/checkbox"
android:layout_height="wrap_content" android:clickable="true"/>
Upvotes: 6