简体   繁体   中英

Android RatingBar rating is not set correctly

I use two RatingBars in my xml layout:

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="0.25"
    android:rating="4.25"/>

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="0.25"
    android:rating="4.5"/>

Even though I set ratings to 4.25 and 4.5 , both RatingBars display wrong number of stars filled. On an Android 6 device it looks like this:

ratingBars

On an android 4.3 device, it looks like this:

ratingBars

But on xml design view, I can see 4.25 and 4.5 are set. Can anyone tell me why? I do not do anything with the rating bars in my code).

Thanks.

In my opinion the problem is related to android:progressTint ,android:progressBackgroundTint & android:secondaryProgressTint . Try to add following lines to your rating bar:

android:progressTint="Color1"
android:progressBackgroundTint="Color2"
android:secondaryProgressTint="Color3"

also try to add style to your rating bar as following:

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

and finally add a the following line in your rating bar

style="@style/RatingBar"

It will work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM