Android更换RatingBar图片
2010-06-19 17:47:00 来源:WEB开发网RatingBar是我们在系统显示分数的好组件,但是我们一般想把RatingBar装饰的更好看,想把更好看的图片用来替换系统默认的图片,系统默认的样子是这样的:
下图是个不错的选择哦:
想要实现如上效果,首先我们在styles.xml写入一个样式:
Xml代码
< ?xml version="1.0" encoding="utf-8"?>
< resources>
< style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
< item name="android:progressDrawable">@drawable/food_ratingbar_full
< item name="android:minHeight">48dip
< item name="android:maxHeight">48dip
< /style>
< /resources>
< ?xml version="1.0" encoding="utf-8"?>
< resources>
< style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
< item name="android:progressDrawable">@drawable/food_ratingbar_full
< item name="android:minHeight">48dip
< item name="android:maxHeight">48dip
< /style>
< /resources>
然后在Drawable文件夹下建food_rating_bar_full.xml文件,内容如下:
Xml代码
< ?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/food_ratingbar_full_empty" />
< item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/food_ratingbar_full_empty" />
< item android:id="@+android:id/progress"
android:drawable="@drawable/food_ratingbar_full_filled" />
更多精彩
赞助商链接