Android changing the stars of rating bar with images you like

Updated 25 July 2018

Save

In this Blog, we will learn on how to change the rating bar content with your own custom images, (images can be any thing like a star with your own colour and background of your choice, or anything that you want to represent the rating with).

Please note that here we will try to change the icon of star with our own, that is one image of ours will represent a unit of rating.

Implementing this is very easy, let’s have a look on how to do it :

  1. Create a new drawable file with layer list as parent tag. (say,my_rating_display)
  2. Add three items in it with ids “@android:id/background” , “@android:id/secondaryProgress”, “@android:id/progress” respectively.
  3. Create a drawable or image that you want to set as background(when rating will be zero). and add it to the item with id background.
  4. Create a drawable or image that you want to set as filled star(when rating will be one). and add it to the item with id progress.
  5. Create a drawable or image that you want to set as half star(when rating will be one). and add it to the item with id progress.
  6. Now set the attribute “progressDrawable” to my_rating_display.

And it is done.

CODE :

my_rating_display.xml

And the code of Rating bar :

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


4 comments

  • Howard
    • anchit (Moderator)
  • hila
    • anchit (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home