2

How can I change the starts image in the android rating bar?

I need it to show it to the user.

Or if not possible - how can show X images of start in a specific possition in the layout?

Yoav

N West
  • 6,768
  • 25
  • 40
Yoav
  • 635
  • 2
  • 11
  • 29

2 Answers2

7

I hope I understod your question - you want to use RatingBar and set custom images?

Android's RatingBar already displays stars, but if you want custom image then Define a custom style

<style name="customRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/custom_image</item>
    <item name="android:indeterminateDrawable">@drawable/custom_image</item>
</style>

And then use it

<RatingBar style="@style/customRatingBar" ... /> 
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
0

First create one drawable

 <?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/rating_bar_empty" />
    <item
        android:id="@android:id/secondaryProgress"

        android:drawable="@drawable/rating_bar_empty" />
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/rating_bar_filled" />
</layer-list>

then use drawable in rating bar attribute `android:progressDrawable="@drawable/drawable_rating_stars"'

 <RatingBar
                    android:id="@+id/ratingBar"
                    style="?android:attr/ratingBarStyleIndicator"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:isIndicator="false"
                    android:numStars="5"
                    android:progressDrawable="@drawable/drawable_rating_stars"
                    android:scaleX="1"
                    android:scaleY="1"
                    android:stepSize="1.0" />
Kishan Thakkar
  • 619
  • 6
  • 11