另一种方法是创建自定义评分栏,如果您没有任何图像,请按照以下步骤操作。所有文件都在drawable文件夹中创建。
< p >< strong > emptystar.xml < / strong >< / p >
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#F1C332" android:pathData="M12,15.39L8.24,17.66L9.23,13.38L5.91,10.5L10.29,10.13L12,6.09L13.71,10.13L18.09,10.5L14.77,13.38L15.76,17.66M22,9.24L14.81,8.63L12,2L9.19,8.63L2,9.24L7.45,13.97L5.82,21L12,17.27L18.18,21L16.54,13.97L22,9.24Z" />
</vector>
full_star.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#F1C332" android:pathData="M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z" />
</vector>
half_star.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M12,15.89V6.59L13.71,10.63L18.09,11L14.77,13.88L15.76,18.16M22,9.74L14.81,9.13L12,2.5L9.19,9.13L2,9.74L7.45,14.47L5.82,21.5L12,17.77L18.18,21.5L16.54,14.47L22,9.74Z" >
</path>
</vector>
food_ratingbar_full_empty.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/empty_star" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/empty_star" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/empty_star" />
<item android:drawable="@drawable/empty_star" />
food_ratingbar_full_filled.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/full_star" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/full_star" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/full_star" />
<item android:drawable="@drawable/full_star" />
food_rating_bar.xml
<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" />
style.xml
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/food_rating_bar_full</item>
<item name="android:minHeight">23dip</item>
<item name="android:maxHeight">25dip</item>
</style>
在你的布局中
<RatingBar
android:id="@+id/ratingBarDish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp10"
android:layout_marginStart="@dimen/dp10"
style="@style/foodRatingBar"
android:isIndicator="true" />