Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change android rating Bar stars?

I am trying to change the stars of my rating bar by creating new style, this what i did :

<style name="RatingBarSmall" parent="android:Widget.DeviceDefault.Light.RatingBar.Indicator">
        <item name="android:progressDrawable">@drawable/rating_bar</item>
        <item name="android:minHeight">36dp</item>
        <item name="android:maxHeight">36dp</item>
    </style>

drawable/rating_bar:

<?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_star_empty" />
    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/rating_star_empty" />
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/rating_star_filled" />
</layer-list>

rating bar xml view:

<RatingBar
                    android:id="@+id/ratingBar"
                    style="@style/RatingBarSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:isIndicator="true"
                    android:rating="5" />

and here is the tow images:

rating_star_empty rating_star_filled

but i don't know why i got vertical lines under the stars as you can see int the bellow picture: enter image description here

EDIT: SOLVED:i just set the rating bar height as the image height.

thanks

like image 659
david Avatar asked Nov 16 '15 08:11

david


1 Answers

I observe this problem in this way. You may create any values in res/values/dimens.xml for each screen (mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi) like:

<dimen name="rating_min_height">36dp</dimen>
<dimen name="rating_min_width">36dp</dimen>

And use this:

<style name="RatingBarSmall" parent="android:Widget.DeviceDefault.Light.RatingBar.Indicator">
    <item name="android:progressDrawable">@drawable/rating_bar</item>
    <item name="android:minHeight">@dimen/rating_min_height</item>
    <item name="android:maxHeight">@dimen/rating_min_width</item>
</style>

Or you can apply that logic to your drawable (rating_star_empty and rating_star_filled)

like image 158
walkmn Avatar answered Nov 02 '22 18:11

walkmn