Change ratingbar for Android

Source: Internet
Author: User

From: http://www.iteye.com/topic/689272

Ratingbar is a good component for us to display scores in the system. However, we generally want to make ratingbar better decorated and use better-looking images to replace the default images of the system, the default format is as follows:
 
It's a good choice:
 
To achieve the above effect, first write a style in styles. xml:

XML Code
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Resources>
  3. <Style name = "foodratingbar" parent = "@ Android: style/widget. ratingbar">
  4. <Item name = "Android: progressdrawable"> @ drawable/food_ratingbar_full </item>
  5. <Item name = "Android: minheight"> 48dip </item>
  6. <Item name = "Android: maxheight"> 48dip </item>
  7. </Style>
  8. </Resources>


Create the food_rating_bar_full.xml file in the drawable folder. The content is as follows:
XML Code

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Layer-list xmlns: Android = "http://schemas.android.com/apk/res/android">
  3. <Item Android: Id = "@ + Android: ID/background"
  4. Android: drawable = "@ drawable/food_ratingbar_full_empty"/>
  5. <Item Android: Id = "@ + Android: ID/secondaryprogress"
  6. Android: drawable = "@ drawable/food_ratingbar_full_empty"/>
  7. <Item Android: Id = "@ + Android: ID/progress"
  8. Android: drawable = "@ drawable/food_ratingbar_full_filled"/>
  9. </Layer-List>


Food_ratingbar_full_empty indicates that the image is not selected, and food_ratingbar_full_filled indicates that the image is selected.
Put the style in ratingbar to achieve your image effect:
XML Code

  1. <Ratingbar Android: Id = "@ + ID/my_rating_bar"
  2. ...
  3. Style = "@ style/foodratingbar"/>

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.