Android RatingBar Example

In this tutorial you will learn about Android RatingBar with example.

RatingBar is widget in android that is used to show user rating in the form of stars. The user can drag or touch it to set the rating value. Rating bar is very import widget specially for eCommerce apps where we have to display user rating.

To use rating bar in android just add a <RatingBar> tag in layout xml file. Some of its important attributes are given below.

Attribute Java Method Description
android:rating setRating(float rating) Used to assign default rating value.
android:numStars setNumStars(int numStars) Used to set number of starts in rating bar. If you use this attribute then make sure rating bar width is wrap content.
android:isIndicator setIsIndicator(boolean) If boolean value is true then rating bar act as indicator and user can’t change its value. Rating bar is changeable if boolean value is false. By default rating bar is changeable.
android:stepSize setStepSize(float stepSize) Used to set rate of increase and decrease. If step size is 1.0 then rating bar value will increase or decrease by 1.0.

Use getRating() method to get the current value of rating bar. Apply setOnRatingBarChangeListener to rating bar to get rating value whenever it changes.

Below example show how to implement rating bar in android.

Android RatingBar Example

Make an android studio project with package name com.androidratingbar.

Now add following code in respective files.


Save and run the project.

When you will touch or drag your finger over rating bar then its value will be changed and displayed in textview.


Android RatingBar Example

Comment below if you have queries or found anything incorrect in above android rating bar example.

Leave a Comment

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