【问题标题】:How to change the star images of the RatingBar?如何更改 RatingBar 的星图?
【发布时间】:2010-10-11 02:13:39
【问题描述】:

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

谢谢。

【问题讨论】:

    标签: android ratingbar


    【解决方案1】:

    不确定 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>
    

    无需继承 RatingBar,只需使用 'style' 属性将此样式传递给它:

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

    下载 android 源代码并查看 core drawable 文件夹中的 ratingbar_full.xml 以查看要放入 my_ratingbar_full 的内容。

    您可以在此处找到更完整的版本: How to create Custom Ratings bar in Android

    【讨论】:

    • 是否可以通过编程方式更改它?
    • 如果您以编程方式创建 RatingBar,您可以将样式作为最后一个参数传递给其构造函数 RatingBar(Context context, AttributeSet attrs, int defStyle)
    【解决方案2】:

    简短的回答是它看起来在技术上是可行的。最简单的方法是根据 RatingBar 源代码创建您自己的 RatingBar(更优雅的是 extend 将原始 RatingBar 放入您自己的)。从那里您还需要创建自己的 RatingBar 样式,使用原始 RatingBar 源 xml 作为示例(或继承和扩展原始 RatingBar 样式)。

    在 developer.android.com 上可以使用 git 获取源代码。

    我怀疑不鼓励自己制作评分栏,因为它违背了操作系统的一致外观。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2011-04-20
      • 1970-01-01
      • 2012-09-05
      相关资源
      最近更新 更多