我正在尝试在所有设备中将评级栏星形颜色设置为单一颜色。目前我在styles.xml中使用样式定义设置星形颜色,但它不起作用。请帮帮我们。 问候, 感谢。
答案 0 :(得分:1)
首先在评级栏中设置此样式
1)样式
<style name="customRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/custom_ratingbar</item>
<item name="android:minHeight">@dimen/search_ratingbar_height_width</item>
<item name="android:maxHeight">@dimen/search_ratingbar_height_width</item>
</style>
2)custom_ratingbar.xml
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="@android:id/background"
android:drawable="@drawable/start_blank" />
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/start_blank" />
<item
android:id="@android:id/progress"
android:drawable="@drawable/star_filed" />
3)start_blank.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/star_blank" android:state_pressed="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_blank" android:state_focused="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_blank" android:state_selected="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_blank" />
4)star_filed.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/star_filed" android:state_pressed="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_filed" android:state_focused="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_filed" android:state_selected="true" android:state_window_focused="true" />
<item android:drawable="@drawable/star_filed" />
注意:在最后两个xml文件中,star_filed和star_blank是用作drawable的png文件...相应地设置资源...