Android 如何更改 RatingBar 的星图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/607610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:20:32  来源:igfitidea点击:

How to change the star images of the RatingBar?

androidratingbar

提问by Chang Chung

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

Android SDK 1.1 r1没有什么办法可以RatingBar用我自己的方式更改小部件类的星形图像?这可能吗?如果是,那又如何?

Thanks.

谢谢。

采纳答案by Will

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 extendthe 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).

简短的回答是它看起来在技术上是可能的。最简单的方法是根据 RatingBar 源代码创建您自己的 RatingBar(更优雅的是extend将原始 RatingBar 放入您自己的)。从那里,您还需要使用原始 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.

我怀疑不鼓励制作自己的评分栏,因为它与操作系统的一致外观和感觉背道而驰。

回答by kozyr

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

不确定 1.1,但在 1.6 及更高版本中,您可以扩展Widget.RatingBar样式并覆盖负责星形可绘制对象的属性(在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 源代码并查看核心 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 中创建自定义评分栏