Ratingbar is a control that we often use to display scores or levels, but the background of the system is monotonous. Therefore, we want to make him more personalized. Replace the default image with a better image.
The above is the system, and the below is after I change my favorite picture (I have no good-looking pictures, so I just chose two pictures, which is not very nice ...)
The procedure is simple:
<RatingBar android:id="@+id/ratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="5"/> <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/ratingbar" android:layout_below="@+id/ratingbar" android:layout_marginTop="42dp" android:numStars="5" style="@style/MyStarRatingBar" />
You can modify the style attributes. Below is the code for mystarratingbar
<style name="MyStarRatingBar" parent="@android:style/Widget.RatingBar"> <item name="android:progressDrawable">@drawable/rating_bar</item> <item name="android:minHeight">30dip</item> <item name="android:maxHeight">30dip</item> </style>
Then there is the code for rating_bar, under 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/kongxing"></item> <item android:id="@+android:id/secondaryProgress" android:drawable="@drawable/kongxing"></item> <item android:id="@+android:id/progress" android:drawable="@drawable/manxing"></item></layer-list>
Kongxing indicates the unselected image, and manxing indicates the selected Tup.
Reference: http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/