【问题标题】:Android : Removing border in rating barAndroid:删除评级栏中的边框
【发布时间】:2015-12-02 12:01:27
【问题描述】:

我在 android 中使用默认的rating bar,并且显示了一个奇怪的灰色边框,我想删除它们。

请注意 :: stackoverflow 上的许多答案建议使用自己的图像,但我不想,有什么方法可以去除边框吗?

我的代码::

  <RatingBar
    android:id="@+id/layout_fragment_home_recycler_view_rating_bar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="1.0"
    android:rating="4.0"
    style="?android:attr/ratingBarStyleSmall"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="7dp"
    android:layout_marginLeft="7dp" />

我得到了什么

【问题讨论】:

  • 你能给我们看看这里的图片吗
  • 更新您的答案,以便我们为您提供帮助
  • @Ravi 你说的是哪个灰色边框?选定星星周围的边框?
  • @Soham Yes 围绕选定的星星边框
  • @Ravi 我认为这是不可能的。您必须使用您的自定义样式。

标签: java android xml ratingbar


【解决方案1】:

只需删除

style="?android:attr/ratingBarStyleSmall"

从你的布局

【讨论】:

    【解决方案2】:

    为您的评分栏创建自定义样式

    <style name="RatingBarStyle" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/ratingbar_selector</item>
        <item name="android:minHeight">34dp</item>
        <item name="android:maxHeight">34dp</item>
    </style>
    

    您的评分栏选择器

    drawable/ratingbar_selector.xml

    <item android:id="@+android:id/background" 
        android:drawable="@drawable/..." />
    
    <item android:id="@+android:id/secondaryProgress"
        android:drawable="@drawable/..." />
    
    <item android:id="@+android:id/progress"
        android:drawable="@drawable/..." />
    

    【讨论】:

    • 我不想使用drawable,我在我的问题中提到过。
    • 请问还有其他解决方案吗?
    • 然后提供您的xml代码以及您的图像的外观,可能是您错过了一些属性
    • 编辑后的代码请检查
    【解决方案3】:

    这对我有用:

    RatingBar coachRating = (RatingBar) findViewById(R.id.rcoach_rbr_rating);
    LayerDrawable stars = (LayerDrawable) coachRating.getProgressDrawable();
    stars.getDrawable(2).setColorFilter(ContextCompat.getColor(itemView.getContext(), 
                            R.color.colorAccent),PorterDuff.Mode.SRC_ATOP); // for filled stars
    stars.getDrawable(1).setColorFilter(ContextCompat.getColor(itemView.getContext(), 
                            R.color.white), PorterDuff.Mode.SRC_ATOP); // for half filled stars
    stars.getDrawable(0).setColorFilter(ContextCompat.getColor(itemView.getContext(), 
                            R.color.white), PorterDuff.Mode.SRC_ATOP); // for empty stars
    

    参考:How can I set the color of android rating bar's stroke? (Not the color of the stars but the BORDER)

    【讨论】:

      【解决方案4】:

      试试这个,它不需要图片。

      public static void setRatingStyle(RatingBar ratingbar, int ratingNormalColor, int ratingProgressColor) {
          LayerDrawable stars = (LayerDrawable) ratingbar.getProgressDrawable();
          stars.getDrawable(0).setColorFilter(ratingNormalColor, PorterDuff.Mode.SRC_ATOP);
          stars.getDrawable(2).setColorFilter(ratingProgressColor, PorterDuff.Mode.SRC_ATOP);
      }
      

      【讨论】:

      • 它只改变颜色,不去除边框
      • 我认为没有drawables是不可能的
      猜你喜欢
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      相关资源
      最近更新 更多