Customize the look of checkbox starStyle

android, android-checkbox

Solution

I resolved this as follows. I created a file in `res/drawable` called `btn_star_selector.xml` and defined the selector as follows:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_checked="true" android:state_pressed="true"  android:drawable="@drawable/btn_star_on_pressed" />
     <item android:state_checked="false" android:state_pressed="true"
      android:drawable="@drawable/btn_star_off_pressed" />
     <item android:state_checked="true" android:drawable="@drawable/btn_star_on" />
     <item android:state_checked="false" android:drawable="@drawable/btn_star_off" />
</selector>

With this selector defined I then replaced this line in the `checkbox` definition

style="?android:attr/starStyle"

with this

android:button="@drawable/btn_star_selector"

I then created four images to represent the different states of the checkbox, namely `on`, `off`, `on pressed` and `off pressed` and also placed these in `res/drawables`.

Hope this helps anyone else that is trying to figure out how to customize checkboxes.

Problem

I the following inside the xml layout for my `ListView` row: ``` <CheckBox android:id="@+id/favbutton" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" /> ``` And it shows a blue star which can be checked to select a favourite. This is exactly the functionality that I need, but I just would like to customize the star icon that is shown. I would like to change the colour to yellow instead of blue and also make the star smaller if possible. Is it possible to make these changes by making changes to the theme applied to the application? What would I need to edit to change the look of the star icon?

Original source

Related problems