How to change the star images of the RatingBar?

只谈情不闲聊 提交于 2019-12-28 03:35:06

问题


With Android SDK 1.1 r1, is there any way to change the RatingBar widget class's star image with my own? Is this possible at all? If so, then how?

Thanks.


回答1:


The short answer is it looks like it's techincally possible. The easiest way would be to create your own RatingBar based on the RatingBar sourcecode (more elegant would be to extend the orignal RatingBar into your own). From there you would also need to create your own RatingBar style using the original RatingBar source xml as an example (or inheriting and extending the original RatingBar style).

Source is available wtih git at developer.android.com.

I suspect making your own rating bar is discouraged since it goes against the consistent look and feel of the OS.




回答2:


Not sure about 1.1, but with 1.6 and later you can just extend Widget.RatingBar style and override the properties that are responsible for star drawables (in values/styles.xml):

 <style name="myRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/my_ratingbar_full</item>
        <item name="android:indeterminateDrawable">@drawable/my_ratingbar_full</item>
 </style>

There's no need to subclass RatingBar, just pass this style to it with the 'style' attribute:

<RatingBar style="@style/myRatingBar" ... /> 

Download android sources and look at the ratingbar_full.xml in the core drawable folder to see what to put into my_ratingbar_full.

You can find a fuller version of this here: How to create Custom Ratings bar in Android



来源:https://stackoverflow.com/questions/607610/how-to-change-the-star-images-of-the-ratingbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!