Last Updated:

RatingBar in Android with Example

RatingBar in Android

The RatingBar widget is used in Android to get a rating of something from a user. The very result of pressing one of the stars is returned as a floating-point number.

Example of working with the RatingBar widget in Android

Let's look at the most important attributes:RatingBar

  • attribute sets the number of stars in android:numStarsRatingBar
  • android:stepSize — fills in the asterisk after the user clicks on it. For example, if you specify in 0.5, then by clicking on the star of the widget, only half of it will be painted.stepSizeRatingBar
  • android:isIndicator whether this is clickable for the user.RatingBar
  • The attribute makes the widget's asterisks"?android:attr/ratingBarStyleSmall"RatingBar

Important points in RatingBar:

The method returns a rating value.getRating()

The implementation of the interface obliges us to override the method that tracks the change in the rating in the widget:




In this tutorial, we'll display the rating of the RatingBar widget in a toast (pop-up window):

XML layout:

Please note, we have specified 6 stars in the widget and the rating change step is 0.5.

Class Listing :MainActivity