Change ratingbar background image for Android

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.