Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

android - How to change the star images of the RatingBar?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...