Android SeekBar

Android SeekBar Tutorial and Examples

A SeekBar is an extension of ProgressBar that adds a draggable thumb.

The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

Normally Clients of the SeekBar can attach a SeekBar.OnSeekBarChangeListener to be notified of the user's actions. SeekBar.OnSeekBarChangeListener is a callback that notifies clients when the progress level has been changed. This includes changes that were initiated by the user through a touch gesture or arrow key/trackball as well as changes that were initiated programmatically.

API Definition

SeekBar resides in the android.widget package and derives from the android.widget.AbsSeekBar class.

public class SeekBar extends AbsSeekBar 

Here's the inheritance chain of seekbar:

   ↳    android.view.View
       ↳    android.widget.ProgressBar
           ↳    android.widget.AbsSeekBar
               ↳    android.widget.SeekBar

Important Methods

(a). onProgressChanged

public abstract void onProgressChanged (SeekBar seekBar, 
                int progress, 
                boolean fromUser)

Notification that the progress level has changed. Clients can use the fromUser parameter to distinguish user-initiated changes from those that occurred programmatically.

The parameters are:

  1. SeekBar - The SeekBar whose progress has changed
  2. progress int: The current progress level. This will be in the range min..max where min and max were set by ProgressBar.setMin(int) and ProgressBar.setMax(int), respectively. (The default values for min is 0 and max is 100.)
  3. fromUser boolean: True if the progress change was initiated by the user.

(b). onStartTrackingTouch

public abstract void onStartTrackingTouch (SeekBar seekBar)

Notification that the user has started a touch gesture. Clients may want to use this to disable advancing the seekbar.

The Parameters are:

  1. seekBar SeekBar: The SeekBar in which the touch gesture began

(c). onStopTrackingTouch

public abstract void onStopTrackingTouch (SeekBar seekBar)

Notification that the user has finished a touch gesture. Clients may want to use this to re-enable advancing the seekbar.

The Parameters are:

  1. seekBar SeekBar: The SeekBar in which the touch gesture began

The above methods are not defined directly in seekbar class but inside the OnSeekBarChangeListener interface. However that interface resides in the seekbar class.

SeekBar Examples

1. SeekBar Example - Show Progress in a TextView

Here's the code for first example:


Here's our main activity.

import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener{

    private SeekBar seekBar ;  
    private TextView tv1 ;  
    private TextView tv2 ;  

    protected void onCreate(Bundle savedInstanceState) {
        seekBar = (SeekBar) findViewById(;
        tv1 = (TextView) findViewById(;
        tv2= (TextView) findViewById(;


     * Value change 
     * @param seekBar 
     * @param progress 
     * @param fromUser 
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        tv1.setText("dragging" );
        tv2.setText("current value: " + progress );

     * Start dragging 
     * @param seekBar 
    public void onStartTrackingTouch(SeekBar seekBar) {
        tv1.setText("start dragging");

    // Stop the move 
    public void onStopTrackingTouch(SeekBar seekBar) {
        tv1.setText("stop dragging");

(b). main.xml

Here's the main layout for activity. Here we will have a Seekbar as well as several TextViews. We organize them vertically with a LinearLayout.

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


How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:


What do You Think

Previous Post Next Post