Skip to content
Related Articles

Related Articles

Android | Creating a SeekBar
  • Last Updated : 23 Feb, 2021

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.

Below are the steps for Creating SeekBar Android Application:

  • Step1: Create a new project. After that, you will have java and XML file.

  • Step2: 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. Assigne ID to SeekBar And TextView.

  • Step3: Now, open up the activity java file and then define the SeekBar and TextView variable, use findViewById() to get the SeekBar and TextView.
  • Step4: Performs seek bar change listener event which is used for getting the progress value. By using this event listener we get the value of Prograss, and the progress is displayed by using a TextView, which will increase the size.
  • Step5: Now run the app and touch the thumb and then Drag it, the Text size will increase automatically.

The complete code of or activity_main.xml of SeekBar is given below:


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

package org.geeksforgeeks.navedmalik.seekbar;
// Import the libraries
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    // Define the global variable
    SeekBar seekbar;
    TextView Text_message;
    protected void onCreate(Bundle savedInstanceState)
        // Binding the layout to the file
        // use findViewById() to get the Button
            = (TextView)findViewById(;
            = (SeekBar)findViewById(;
        // Get the progress value of the SeekBar
        // using setOnSeekBarChangeListener() method
                new SeekBar
                    .OnSeekBarChangeListener() {
                        // When the progress value has changed
                        public void onProgressChanged(
                            SeekBar seekBar,
                            int progress,
                            boolean fromUser)
                            // increment 1 in progress and
                            // increase the textsize
                            // with the value of progress
                            message.setTextSize(progress + 1);
                        public void onStartTrackingTouch(SeekBar seekBar)
                            // This method will automatically
                            // called when the user touches the SeekBar
                        public void onStopTrackingTouch(SeekBar seekBar)
                            // This method will automatically
                            // called when the user
                            // stops touching the SeekBar


Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :