Nikoloz14 Nikoloz14 - 3 months ago 14
Android Question

Android: Color of stars in RatingBar, that already uses style

I want to change colour of RatingBar stars in every mode(highlighted, notHighlited, progress), but I already use style Widget.AppCompat.RatingBar.

I don't want to change style cause, I like star shapes and staff, I only want to change star colors, Is it possible?

Here's my code:

<RatingBar
android:id="@+id/ratingBar"
style="@style/Widget.AppCompat.RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:layout_gravity="center_horizontal"
android:rating="0.0" />

Answer

Use styles:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background" android:drawable="@drawable/background" />
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/secondary_progress" />
    <item android:id="@android:id/progress" android:drawable="@drawable/progress" />
</layer-list>

You can use this style following way. Add this line to the RatingBar:

android:progressDrawable="@drawable/rating"