1

I am trying to set the rating bar star color to a single color in all the devices. Currently I am setting the star color using style definition in styles.xml, but it is not working. Please help me out guys. Regards, Thanks.

1 Answers1

1

First of all set this style in your ratingbar

1) Style

<style name="customRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/custom_ratingbar</item>
    <item name="android:minHeight">@dimen/search_ratingbar_height_width</item>
    <item name="android:maxHeight">@dimen/search_ratingbar_height_width</item>
</style>

2) custom_ratingbar.xml

<?xml version="1.0" encoding="utf-8"?>

<item
    android:id="@android:id/background"
    android:drawable="@drawable/start_blank" />
<item
    android:id="@android:id/secondaryProgress"
    android:drawable="@drawable/start_blank" />
<item
    android:id="@android:id/progress"
    android:drawable="@drawable/star_filed" />

3) start_blank.xml

<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/star_blank" android:state_pressed="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_blank" android:state_focused="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_blank" android:state_selected="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_blank" />

4) star_filed.xml

<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/star_filed" android:state_pressed="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_filed" android:state_focused="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_filed" android:state_selected="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_filed" />

Note: in last two xml file, star_filed and star_blank is png file used as drawable...set that resources accordingly...

Bhavnik
  • 1,747
  • 9
  • 18
  • Thanks for your reply. But I do not want to create a custom star. Anyways thanks once again, in case if I need it in future I will have a look at it. – Avinash Jaiswal Oct 22 '16 at 09:54