简体   繁体   English

如何更改RatingBar的星形图像?

[英]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? 使用Android SDK 1.1 r1 ,有没有办法用我自己的方式更改RatingBar小部件类的星形图像? Is this possible at all? 这有可能吗? If so, then how? 如果是这样,那怎么样?

Thanks. 谢谢。

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 ): 不确定1.1,但是1.6及更高版本你可以扩展Widget.RatingBar样式并覆盖负责star drawables的属性(在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'属性将此样式传递给它:

<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 . 下载android源代码并查看core drawable文件夹中的ratingbar_full.xml以查看要放入my_ratingbar_full

You can find a fuller version of this here: How to create Custom Ratings bar in Android 您可以在此处找到更全面的版本: 如何在Android中创建自定义评级栏

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). 最简单的方法是根据RatingBar源代码创建自己的RatingBar(更优雅的是extend orignal RatingBar扩展为您自己的)。 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). 从那里你还需要使用原始的RatingBar源xml作为示例创建自己的RatingBar样式(或继承和扩展原始的RatingBar样式)。

Source is available wtih git at developer.android.com. 源代码可以通过developer.android.com上的git获得。

I suspect making your own rating bar is discouraged since it goes against the consistent look and feel of the OS. 我怀疑制作自己的评级栏是不受欢迎的,因为它违背了操作系统的一致外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM