Search code examples
androidandroid-support-libraryratingbarandroid-support-design

Android RatingBar ratingBarStyleSmall only show full/ filled stars


It doesn't even show any half star! Of course, I've ready all the other questions, they contain no magic I haven't tried.

I tried changing the style to ratingBarStyleand there is half star but of course, normal size RatingBar does not meet my requirements here.

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <RatingBar
            android:id="@+id/ratingBar2"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:isIndicator="true"
            android:backgroundTint="@color/colorAccent"
            android:progressTint="@color/colorAccent"
            android:secondaryProgressTint="@color/colorAccent"
            android:numStars="5"
            android:rating="3.3"
            android:stepSize="0.1"/>
    </LinearLayout>

My Java code:

ratingBar.setStepSize(0.1f);
ratingBar.setRating(3.5f);

Result I'm seeing:
enter image description here

I'm using Android Support version 23.4.0. My compileSdkVersion and targetSdkVersion are both 23. I'm testing on a Android 5.0 device.


Solution

  • Remove or change the android:secondaryProgressTint. It is used to fill the last (partial) star. This is what I get with :

        <RatingBar
            android:id="@+id/ratingBar2"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:isIndicator="true"
            android:backgroundTint="#f00"
            android:progressTint="#0f0"
            android:secondaryProgressTint="#00f"
            android:numStars="5"
            android:rating="3.3"
            android:stepSize="0.1"/>
    

    Rating bar with partial star

    I only changed the 3 colors. It seems that the background tint is not used at all (AppCompat 23.4.0, API 22 device).