Android RatingBar

RatingBar can be defined as below –

"Android RatingBar can be used to get the rating from the user. The Rating returns a floating-point number. It may be 2.0, 3.5, 4.0 etc. Android RatingBar displays the rating in stars. Android RatingBar is the subclass of AbsSeekBar class."

Attributes of Android RatingBar

Some of the popular attributes of android ratingbar are –





S. No. XML Attributes Description
1 android:id Sets id of the view. Note – Id must always be unique in an xml file.
2 android:padding Sets padding(left, right, top, bottom) to the view.
3 android:visibility Sets visibility(show/hide) of the view.
4 android:background Sets background of the view
5 android:isIndicator Specifies whether this rating bar is an indicator. Note – It can’t be changed by the user if it is an indicator.
6 android:numStars Specifies the number of stars(or rating items) to show.
7 android:rating Specifies the rating to show by default.
8 android:stepSize Specifies the step size of the rating.

Some of the popular attributes of android ratingbar inherited from AbsSeekBar are –

S. No. XML Attributes Description
1 android:thumbTint Tint to apply to thumb drawable.
2 android:thumbTintMode Blending mode used to apply the thumb tint.
3 android:tickMarkTint Tint to apply to the tick mark drawable.
4 android:tickMarkTintMode Blending mode used to apply the tick mark tint.

Some of the popular attributes of android RatingBar inherited from ProgressBar are –





S. No. XML Attributes Description
1 android:maxHeight Sets maximum height of the view.
2 android:minHeight Sets minimum height of the view.
3 android:maxWidth Sets maximum width of the view.
4 android:minWidth Sets minimum width of the view.

At first, we'll create android application. Then, we will use ratingbar in this application.

Follow the steps below to create new application. Please ignore the steps if you've already created the application.

S. No. Steps
1 Open Android Studio.
2 Click on Start a new Android Studio Project Write application name as RatingBar. Then, click next button.
3 Select minimum SDK you need. However, we have selected 14 as minimum SDK. Then, click next button
4 Then, select Empty Activity => click next => click finish.
5 If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit tutorial to Create a New Project to know steps in detail.

Now, we'll modify the xml and java file to use ratingbar in this application.





Open res/values/strings.xml file. Then, add below code into it.

<string name="app_name">RatingBar</string>

Open res/layout/activity_main.xml file. Then, add below code into it.

<?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""

android:stepSize="0.5" />

app:layout_constraintTop_toTopOf="@id/ratingbar" />


In activity_main.xml file, we have used ratingbar and button. In RatingBar, android:stepSize=”0.5″ attribute is used to set incremental steps. Now, we will access these ratingbar and button in java file.

RatingBar in java file

Open src/main/java/com.ukacademe.ratingbar/ file. Then, add below code into it.

package com.ukacademe.ratingbar;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        final RatingBar ratingBar = findViewById(;
        if (ratingBar != null) {
            Button button = findViewById(;
            if (button != null) {
                button.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        String msg = String.valueOf(ratingBar.getRating());
                        Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();



In, we have accessed ratingbar. We have also set click listener to show toast message when button is clicked. Toast message displays the currently selected rating in ratingbar. Since the file of AndroidManifest.xml is very important in any android application. We are also going to mention it here.

Code inside src/main/AndroidManifest.xml file is as below –

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


When you run the application, we will get output as shown below.

UK Academe-RatingBar-Output