How to Create Android Widgets: SeekBar in Android

Recommended by 4 users

Feb 13,2014
How to Create Android Widgets: SeekBar in Android
Add to Bookmark Email this Post 2.3K    2

This is the next topic after “Rating Bar” in “How to Create Android Widgets” in which we will learn how to use SeekBar in Android. If you are not clear with the basic concepts of Android, please attend this Android Course.

SeekBar is an extension of ProgressBar that adds a dragable thumb. The user can touch/drag or use arrow keys to set the progress when using the SeekBar.

Placing widgets to the left or right of the SeekBar is discouraged.

Usage: Seekbar in Android is generally used to change volume of your device, set brightness of the screen, seeking a song.

how to create android widgets: Seekbar          how to create android widgets: Seekbar

How to create Android Widgets:

Write an Application for SeekBar Android.


how to create android widgets: Drag a Seek Bar from Form Widgets

XML Code:

<RelativeLayout xmlns:android=""
    tools:context=".SeekbarActivity" >

        android:layout_marginTop="142dp" />

        android:textAppearance="?android:attr/textAppearanceLarge" />


  • Working with Android SeekBar is very simple, You only have to use setOnSeekBarChangeListener with SeekBar.
  • Inside the onCreate() method copy the code shown below.

  Java Code:

final TextView tv = (TextView) findViewById(;
SeekBar sb = (SeekBar) findViewById(;

sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
tv.setText("Tracking Started...");

public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
tv.setText("... Tracking Stopped");

public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub

tv.setText("Current Progress:" + progress
+ System.getProperty("line.separator")
+ "Progress changed by User:" + fromUser);

Android SeekBar requires three methods to be implemented:

  • onStartTrackingTouch();Notification that the user has started a touch gesture.
  • onStopTrackingTouch();Notification that the user has finished a touch gesture.
  • onProgressChanged(); – Notification that the progress level has changed.

Local Variables used in the onProgressChanged(); method:

  • int progress : will give you current progress value on the SeekBar. Default range is 0-100.
  • boolean fromUser : Will give you true if Progress is changed by user.

Application Screenshots:

how to create android widgets:Seekbar       how to create android widgets:Seekbar         how to create android widgets:Seekbar

RatingBar Widget is very similar to SeekBar Android, click here to know how to use RatingBar.

Download Code here.

[dl url=”#” class=”eModal eModal-10″ title=”Download Code” desc=”” type=”” align=”” for=”download”]

Have a doubt in the discussed concepts? Ask our experts!

Stay tuned for more tutorials to learn how to create Android widgets! Happy Learning!

The following resources were used for creating this post: Android Developers

You may also like these related posts:

Share on

Browse Categories