Android更换RatingBar图片

/res/values下 styles.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
		<item name="android:progressDrawable">@drawable/food_rating_bar_full</item>
		<item name="android:minHeight">48dip</item>
  		<item name="android:maxHeight">48dip</item>
	</style>
</resources>

 

 

 

/res/Drawable 下 food_rating_bar_full.xml

注意与styles.xml的food_rating_bar_full名称一致

 

 

<?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" />
</layer-list>

 


food_ratingbar_full_empty是代表没有选中图片效果,food_ratingbar_full_filled选中图片效果。
最后将style放入RatingBar中,即可实现你的图片效果:

 

<RatingBar 	android:id="@+id/my_rating_bar"
			...
			style="@style/foodRatingBar" />

 

 

 

 

 

 

 

 

 

Android更换RatingBar图片_第1张图片

 

你可能感兴趣的:(android,RatingBar)