Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Change color of ratingbar to golden [duplicate]

I want to change color of rating bar to golden.
I dont want to customize the stars, i just want to change the color for API 16 or above
I have tried following solutions but none of them worked out for me

1.      RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar); LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);  2.  android:progressDrawable="@color/golden" in XML 
like image 243
ojas Avatar asked Sep 27 '15 16:09

ojas


People also ask

How do I change the color of my RatingBar?

First, change progress color of rating bar. Its done by two ways, either by applying theme on RatingBar or by manually using LayerDrawable. That's it. android:stepSize="0.5" />LayerDrawable stars = (LayerDrawable) rating.

How can change rating bar color in android programmatically?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.

How do I turn off RatingBar touch on Android?

After applying either style="? android:attr/ratingBarStyleSmall" or scaleX/scaleY the click interaction with RatingBar is disabled. This works for me. Hope this helps you!

What is rating bar in Android?

RatingBar is used to get the rating from the app user. A user can simply touch, drag or click on the stars to set the rating value. The value of rating always returns a floating point number which may be 1.0, 2.5, 4.5 etc. In Android, RatingBar is an extension of ProgressBar and SeekBar which shows a rating in stars.


2 Answers

On API 21 and higher, you can change the color of the filled stars with

     android:progressTint="@color/color" 

and the color of the stroke with

     android:progressBackgroundTint="@color/color" 
like image 32
Raseem Ayatt Avatar answered Oct 17 '22 17:10

Raseem Ayatt


This option is now included in the AppCompat library. The AppCompat version of the RatingBar is used automatically.

http://developer.android.com/reference/android/support/v7/widget/AppCompatRatingBar.html

Example (from my own app):

<RatingBar     android:id="@+id/rating"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:numStars="5"     android:stepSize="1"     android:theme="@style/RatingBar"/> 

With theme:

<style name="RatingBar" parent="Theme.AppCompat">     <item name="colorControlNormal">@color/lightGrey</item>     <item name="colorControlActivated">@color/duskYellow</item> </style> 
like image 194
theblitz Avatar answered Oct 17 '22 15:10

theblitz