0

The default color of AndroidBar star color is blue, like this: enter image description here

I want to change the color into green. I've tried several ways, none of them works.

Using android:progressTint

<RatingBar
     android:id="@+id/rb"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:isIndicator="false"
     style="?android:attr/ratingBarStyleSmall"
     android:numStars="5"
     android:stepSize="1"
     android:progressTint="@color/green"
     android:layout_gravity="center"/>

Another attempt. Put a new style in styles.xml:

<style name="RatingBar" parent="Theme.AppCompat">
    <item name="colorControlNormal">@color/iron</item>
    <item name="colorControlActivated">@color/green</item>
</style>

And apply it:

<RatingBar
     android:id="@+id/rb"
     android:theme="@style/RatingBar"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:isIndicator="false"
     style="?android:attr/ratingBarStyleSmall"
     android:numStars="5"
     android:stepSize="1"
     android:layout_gravity="center"/>

My test device is an ASUS phone, running Android 4.4.2. Is there another way, which works on Android 4 and newer? Thank you.

anta40
  • 6,511
  • 7
  • 46
  • 73

2 Answers2

0

You need create two styles in the styles.xml files under values and v21.

Place this style in values/styles.xml file

 <style name="RatingBar" parent="@android:style/Widget.Holo.Light.RatingBar">
        <item name="colorControlNormal">@color/colorAccent</item>
        <item name="colorControlActivated">@color/colorAccent</item>
    </style>

Place this style in v21/styles.xml file

<style name="RatingBar" parent="android:style/Widget.Material.RatingBar">
        <item name="colorControlNormal">@color/colorAccent</item>
        <item name="colorControlActivated">@color/colorAccent</item>
    </style>

In your layout file, use the style like below:

<RatingBar
     android:id="@+id/rb"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:isIndicator="false"
     style="@style/RatingBar"
     android:numStars="5"
     android:stepSize="1"
     android:layout_gravity="center"/>
Madhan
  • 555
  • 5
  • 23
0

Replace style="?android:attr/ratingBarStyleSmall" with style="@style/RatingColor".
In styles.xml, add this:

<style name="RatingColor" parent="Theme.AppCompat">
  <item name="colorControlNormal">@color/blue</item>
  <item name="colorControlActivated">@color/green</item>
</style>
Ajay Kulkarni
  • 2,900
  • 13
  • 48
  • 97