RatingBar in Android Studio - Android Hire
Android Phones

RatingBar in Android Studio

Aditya Singh
In Android, RatingBar is an extension of SeekBar and ProgressBar which shows the rating in stars. RatingBar is a subclass of AbsSeekBar class. The user has to touch and drag to the left and right to set the RatingBar.

In this tutorial, We will show how to display RatingBar in Android Studio. When the user submits the rating, how to take it and say it in Toast Message or Text Field.

RatingBar in Android Studio Tutorial:

1. Create a new project in Android Studio File ⇒ Blank Activity

2. Open the Activity_main.xml file and copy the below code

RatingBar Design

3. Now you have to add the Drawable Resource File in Drawable Folder and name the file as car.xml

" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button">
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24">
    <path android:fillColor="#FF3A00" android:pathData="M16,6L15,6.75L17.5,10H13.5V8.5H12V10H3C1.89,10 1,10.89 1,12V15H3A3,3 0 0,0 6,18A3,3 0 0,0 9,15H15A3,3 0 0,0 18,18A3,3 0 0,0 21,15H23V12C23,10.89 22.11,10 21,10H19L16,6M6,13.5A1.5,1.5 0 0,1 7.5,15A1.5,1.5 0 0,1 6,16.5A1.5,1.5 0 0,1 4.5,15A1.5,1.5 0 0,1 6,13.5M18,13.5A1.5,1.5 0 0,1 19.5,15A1.5,1.5 0 0,1 18,16.5A1.5,1.5 0 0,1 16.5,15A1.5,1.5 0 0,1 18,13.5Z"/>
vector>

4. Open the file style.xml and here we have to add RatingBar Style.

colorControlNormal – The color applied to RatingBar in a normal state where the user has not dragged the RatingBar.

colorControlActivated – The color applied to RatingBar in the activated state where the user has dragged the RatingBar.

#5C5B5B #FFC107 " style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button">
<style name="RatingBar" parent="Theme.AppCompat">
    <item name="colorControlNormal">#5C5B5Bitem>
    <item name="colorControlActivated">#FFC107item>
style>

5. Once you have done the above step, open Mainactivity.java File and do the following changes.

package androidhire.com.ratingbar;

import android.support.v7.app.AppCompatActivity;
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 {

    RatingBar ratingBar;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ratingBar = findViewById(R.id.ratingBar);
        button = findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                float ratingcount = ratingBar.getRating();

                Toast.makeText(getApplicationContext(),"Rating is :" +ratingcount,Toast.LENGTH_LONG).show();
            }
        });
    }
}

Some Tips:

  • Consistency in UI: Make sure the RatingBar fits well with your app's design. It should be easy to spot and use.
  • Feedback: Consider providing immediate feedback when a user selects a rating. It could be a simple toast message or saving the rating to a database.
  • Testing: Test the RatingBar on different devices to ensure it looks and works as expected.

Screenshot

Ratingbar Android Screenshot

DOWNLOAD FROM GITHUB

Aditya Singh's profile picture

Aditya Singh

With over seven years of experience, I help people understand technology through clear and insightful articles. I cover the latest in technology, mobile devices, PCs, how-tos, guides, news, and gadget reviews, always staying updated to provide accurate and reliable information.

Related Posts

7 Top Samsung Galaxy Ring Alternatives for 2025

7 Top Samsung Galaxy Ring Alternatives for 2025

Tired of waiting for the Samsung Galaxy Ring to hit the market? You’re not alone. While the buzz around Samsung’s smart ring continues, a plethora of impressive alternatives is already available. These devices deliver advanced health tracking, stylish designs, and unique features that cater to various lifestyles. The current lineup of smart rings caters to […]

What Is Quiet Mode on Instagram and How to Activate It

What Is Quiet Mode on Instagram and How to Activate It

Ever wondered what Quiet Mode on Instagram is all about? This simple yet powerful Instagram feature helps you take a break from the constant buzz of notifications and focus on what truly matters. Whether you’re striving for better work-life balance, dedicating time to studying, or simply trying to disconnect from social media distractions, Quiet Mode […]

How to Make a Bed in Minecraft (Step-by-Step Guide)

How to Make a Bed in Minecraft (Step-by-Step Guide)

A bed in Minecraft is very important. It lets you skip the night and set your spawn point, so if you die, you will return to your bed instead of the original world spawn. This guide will show you how to gather materials, craft a bed, and set your spawn point. We’ll also show you how to customize your bed, build bunk […]

10 Best MMORPG Games For Android

10 Best MMORPG Games For Android

Not too long ago, MMORPG games and powerful gaming consoles were mostly exclusive to PCs. They required high-end graphics and systems to deliver their immersive gameplay. But times have changed. With the rise of gaming-oriented smartphones, you can now enjoy PC-like gaming experiences on your Android device. Thanks to these technological advancements and faster internet […]

Roblox: Fruit Battlegrounds codes (January 2025)

Roblox: Fruit Battlegrounds codes (January 2025)

Fruit Battlegrounds codes are all about getting more gems and help you to shoot up your rank in this One Piece anime-inspired game. This Fruit Battlegrounds was made by Popo developer. It is an action-packed game where players battle it out using unique fruit-based abilities. With constant updates, new fruits, and exciting challenges, it’s a fruity frenzy you won’t […]

Roblox: Ultimate Football Codes (January 2025)

Roblox: Ultimate Football Codes (January 2025)

Want to get some extra items for Ultimate Football in Roblox? You’ve come to the right place! Here’s the latest list of codes to help you score touchdowns and look stylish on the field. These codes offer free rewards such as coins and cosmetics to enhance your gameplay. What are Ultimate Football Codes? Ultimate Football […]

Roblox: Da Hood Codes (January 2025)

Roblox: Da Hood Codes (January 2025)

Are you a fan of Roblox games, in this article we will look at the Roblox Da Hood Codes for December 2024 that will help you unlock exclusive items, improve your gameplay and dominate the streets of Da Hood. You can feel that the game is inspired by the Grand Theft Auto series and there […]