0

I want to change the color of the stars in rating bar based on user rating. I have tried the following code to change the change the color, but, rather than changing the color of only number of stars user selected, it is changing the color of all the stars.

if(rating.toInt()>=3){
            val drawable = ratingBar.progressDrawable
            DrawableCompat.setTint(drawable, Color.parseColor("#24875A"))
        }
        else{
            val drawable = ratingBar.progressDrawable
            DrawableCompat.setTint(drawable, Color.parseColor("#E20000"))
        }
  • Could be because you are ratingBar is the reference to the whole view. Does this answer your question https://stackoverflow.com/questions/32810341/android-change-color-of-ratingbar-to-golden – Ezio Feb 09 '21 at 06:50
  • Thanks, https://stackoverflow.com/a/49998798/15173963 ans from your link is working for me. – Ayush Agrawal Feb 09 '21 at 11:19

0 Answers0