Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java
  • Android
  • Kotlin
  • Flutter
  • Dart
  • Android with Java
  • Android Studio
  • Android Projects
  • Android Interview Questions
Open In App
Next Article:
Creating a SeekBar in Android
Next article icon

Creating a SeekBar in Android

Last Updated : 13 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Android SeekBar is a type of ProgressBar. On touching the thumb on seekbar and dragging it to the right or left, the current value of the progress changes. SeekBar is used for forwarding or backwarding the songs, Video etc. In the setOnSeekBarChangeListener interface is used which provides three methods.

  1. onProgressChanged: In this method progress is changed and then according to this change the progress value can used in our logic.
  2. onStartTrackingTouch: In this method when the user has started dragging, then this method will be called automatically.
  3. onStopTrackingTouch: In this method, when the user stops dragging, then this method will called automatically.
Dynamic-Seek-Bar

Steps for Implementing SeekBar:

Step 1: Create a new Android Studio project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Step 2: Working with activity_main.xml

Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take. Assign ID to SeekBar And TextView.

activity_main.xml:

XML
<androidx.constraintlayout.widget.ConstraintLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@color/white"     tools:context=".MainActivity">      <TextView         android:id="@+id/message_id"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:layout_marginTop="32dp"         android:text="geeksforgeeks"         android:textSize="20sp"         android:textStyle="bold"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" />      <SeekBar         android:id="@+id/seekbar"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:max="150"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" />  </androidx.constraintlayout.widget.ConstraintLayout> 

Design UI:

design-ui-seekbar


Step 3: Working with MainActivity file

Now, open up the activity file and then define the SeekBar and TextView variable, use findViewById() to get the SeekBar and TextView. Performs seek bar change listener event which is used for getting the progress value. By using this event listener we get the value of Progress, and the progress is displayed by using a TextView, which will increase the size.

MainActivity.java
package org.geeksforgeeks.demo;  import android.os.Bundle; import android.widget.SeekBar; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity;  public class MainActivity extends AppCompatActivity {      private SeekBar seekBar;     private TextView textMessage;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          textMessage = findViewById(R.id.message_id);         seekBar = findViewById(R.id.seekbar);          // Set the SeekBar change listener         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {             @Override             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {                 // Increment 1 in progress and update the text size                 textMessage.setTextSize(progress + 1);             }              @Override             public void onStartTrackingTouch(SeekBar seekBar) {                 // Called when the user starts touching the SeekBar             }              @Override             public void onStopTrackingTouch(SeekBar seekBar) {                 // Called when the user stops touching the SeekBar             }         });     } } 
MainActivity.kt
package org.geeksforgeeks.demo  import android.os.Bundle import android.widget.SeekBar import android.widget.TextView import androidx.appcompat.app.AppCompatActivity  class MainActivity : AppCompatActivity() {      private lateinit var seekBar: SeekBar     private lateinit var textMessage: TextView      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)          textMessage = findViewById(R.id.message_id)         seekBar = findViewById(R.id.seekbar)          // Set the SeekBar change listener         seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {             // When the progress value has changed             override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {                 // Increment 1 in progress and update the text size                 textMessage.textSize = (progress + 1).toFloat()             }              override fun onStartTrackingTouch(seekBar: SeekBar?) {                 // This method will automatically be called when the user touches the SeekBar             }              override fun onStopTrackingTouch(seekBar: SeekBar?) {                 // This method will automatically be called when the user stops touching the SeekBar             }         })     } } 

Output:


Next Article
Creating a SeekBar in Android

N

naved_alam
Improve
Article Tags :
  • Java
  • Android
  • DSA
  • Kotlin Android
  • Android-Bars
  • Java-Android
Practice Tags :
  • Java

Similar Reads

    Creating Custom SeekBar in Android
    SeekBar can be understood as an extension of ProgressBar in Android. You have to just drag the thumb on SeekBar and drag it towards the backward or forward direction and store the current value of progress changed. SeekBar is widely used in different applications ex - Audio player Video Player etc.
    5 min read
    Discrete Seekbar in Android
    Android discrete SeekBar is an extension of ProgressBar that has a draggable thumb. Users can use the thumb back and forth to set the current progress of the SeekBar. Discrete SeekBar works for discrete values.  Step by Step Implementation Step 1: Create a New Project in Android Studio To create a n
    3 min read
    Discrete SeekBar in Android using Library
    Discrete SeekBar is another most common feature that we can see in most of the apps. We can get to see this Discrete SeekBar in most of the music player apps, Rating apps, or for points given. Discrete SeekBar is one of the advanced systems of giving ratings instead of writing. In the previous artic
    3 min read
    Discrete SeekBar in Kotlin
    In Android Discrete SeekBar is just an advancement of progressBar just like the SeekBar, the only difference in SeekBar and discrete SeekBar being that in discrete SeekBar, we can only set the value only to discrete values like 1, 2, 3, and so on. In this article, we will be discussing how to create
    2 min read
    Custom Snackbars in Android
    A Snackbar in Android is a lightweight and quick way to provide feedback to users about an action which is done by the user. It appears as a temporary, dismissible bar at the bottom of the screen and can contain a message and an optional action button which can easily be removed by the user by just
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences