1

I implement the RatingBar in my android project its works perfectly but i want change the ratingbar filling color now defaultly it fill green color,but i want change into another color, below i attached my rating bar image,please any one help me how to change the color of rating bar, thanking you

 https://i.stack.imgur.com/3cN13.png


 **xml code:**

 <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="6dp"
    android:layout_marginTop="5dp"
    android:layout_toRightOf="@id/ratingAndReviewtext"
    android:isIndicator="?android:attr/ratingBarStyleIndicator"
    android:numStars="5"
    android:rating="0.0"
    android:stepSize="0.0" />
Chintan Bawa
  • 1,376
  • 11
  • 15
MurugananthamS
  • 2,395
  • 4
  • 20
  • 49

2 Answers2

9

try following code programatically

 RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
    LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
    stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
krishna
  • 301
  • 1
  • 8
1

Step #1: Create your own style, by cloning one of the existing styles (from $ANDROID_HOME/platforms/$SDK/data/res/values/styles.xml), putting it in your own project's styles.xml, and referencing it when you add the widget to a layout.

Step #2: Create your own LayerDrawable XML resources for the RatingBar, pointing to appropriate images to use for the bar. The original styles will point you to the existing resources that you can compare with. Then, adjust your style to use your own LayerDrawable resources, rather than built-in ones.

Refer : https://stackoverflow.com/a/2447209/3891036


Rating Bar sample & Tutorial : http://www.skholingua.com/android-basic/user-interface/form-widgets/ratingbar

Community
  • 1
  • 1
Yksh
  • 3,276
  • 10
  • 56
  • 101