0

I am using default rating bar in android and there is a weird grey border is been showing, I want to remove them.

Please Note :: Many answers on stackoverflow suggest to use own images but I don't want to, Is there is any method to remove border?

My code ::

  <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" />

What I am getting

enter image description here

Ravi
  • 960
  • 1
  • 18
  • 41

4 Answers4

1

Just remove

style="?android:attr/ratingBarStyleSmall"

From your layout

Leo DroidCoder
  • 14,527
  • 4
  • 62
  • 54
0

Create custom style to your rating bar

<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>

your rating bar selector

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/..." />
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
0

This worked for me:

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

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

Community
  • 1
  • 1
suku
  • 10,507
  • 16
  • 75
  • 120
-1

Try this, it don't need images.

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);
}
Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
Srikanth
  • 1,555
  • 12
  • 20