Android RatingBar Control

Android RatingBar Control

If you want need to rate a movie or website i.e. rating in stars, then use the Android RatingBar control. It is the subclass of android.widget.AbsSeekBar,


Use the Android RatingBar control to show movie reviews, website rating, and product reviews etc.


Here are the attributes of RatingBar Android Control,

RatingBar AttributeDescriptionValue
android:isIndicatorWhether this rating bar is an indicator.true or false
android:numStarsNumber of stars, visible to users.Integer Value
android:ratingSet the default rating with this attribute.Floating Point Value
android:stepSizeSet the step size of the rating.Floating Point Value


The src\main\java\com\studyopedia\studyopediaapplication\ is a java class which sets the views. Here we will set the View to be displayed with the setContentView.

On button click, a Toast will appear with a message showing what rating you have given to the movie using the RatingBar. Toast in Android is a notification message visible in the form of popup.

We’re using getRating() method to retrieve the value of rating. Ratings under RatingBar have floating point value, for example, 2.0, 3.0, 5.0, etc.


For src\main\res\layout\activity_main.xml,

We’ll add our UI content here, 2 TextView, 1 Button and 1 RatingBar. On button click, the rating you entered using RatingBar will get displayed. For displaying the rating, we’ve used Toast,


The content of src\main\AndroidManifest.xml, provides key information of your app to the system. The system needs this to run your code,


Here’s the code for res/values/strings.xml. The app name and any hardcoded strings will be visible. We hardcoded string “Studyopedia RatingBar Application” and used @string/title in activity_main.xml. Here, it gets mentioned under <resources>.

We also hardcoded the review string and used @string/review and result string with @string/result,


We created an AVD, so now we will run our app using the same AVD. Go to Run > Run app or press the run button or Shift + f10. This will install your app on the AVD and the following emulator with your app opens up.

Here’s the output, first screen visible,

Give a rating to the movie and click the RESULT button.

Android ToggleButton Control
Android CheckBox Control
Studyopedia Editorial Staff
Studyopedia Editorial Staff

We work to create free tutorials for all.

No Comments

Post A Comment