Configure starStyle flag view

I have the following inside the xml layout for my ListView line:

  <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 he shows a blue star that you can check to select your favorite. These are exactly the features that I need, but I just would like to customize the star icon that is displayed. I would like to change the color to yellow, not blue, and also make the star smaller if possible. Can these changes be made by changing the theme that applies to the application? What do I need to change to change the appearance of the star icon?

+4
source share
1 answer

I solved it 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, I replaced this line in the checkbox definition

 style="?android:attr/starStyle" 

with this

 android:button="@drawable/btn_star_selector" 

Then I created four images to represent the various states of the checkbox, namely on , off , on pressed and off pressed , and also placed them in res/drawables .

Hope this helps someone else who is trying to figure out how to configure the checkboxes.

+7
source

All Articles