Rating Bar in Android Example

Rating bar is used to get the rating from user and show by star. We can touch/drag or use arrow keys to set the rating when using the default size RatingBar.

RatingBar in Android is a extension of SeekBar and ProgressBar. In this tutorial we learn simple example and use of Rating Bar. Some useful attribute and methods of Rating bar is below.

  • android:isIndicator : Whether this rating bar is an indicator (and non-changeable by the user).
  • android:numStars : to set number of stars (or rating items) to show.
  • android:rating : to set default rating.
  • android:stepSize : The step size of the rating. Like 1.0 or 0.5
  • style=”?android:attr/ratingBarStyleIndicator” : for small Rating Bar
  • getRating() :┬ámethod to get selected rating from RatingBar.

Let’s see simple example of Rating bar.

activity_main.xml

MainActivity.java

Now run project. Our output looks like below.

android-ratingbar-example-output-skynilsDownload Project.
downlod