Android SeekBar

Android SeekBar is an extension of ProgressBar,which contains a thumb which is draggable. The thumb can be moved left or right and can give some actions based on the progress value.The methods provided by  setOnSeekBarChangeListener will help to perform the actions using SeekBar.

Let us seen an example for android seekbar.For implementing SeekBar in android you need to add the following code to your layout file.

<SeekBar
    android:id="@+id/sb_value"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:max="100"/>

Here i am setting the maximum value of seekbar. So this seekbar progress value will be till 100;

And Below is the code for your activity ,You need or refer the seekbar in the layout and need to define setOnSeekBarChangeListener.

SeekBar sb_value = (SeekBar) findViewById(R.id.sb_value);
sb_value.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        Toast.makeText(getApplicationContext(),""+progress,Toast.LENGTH_LONG).show();

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
});

You must get the following output after running the code.

seekbarexample

 

Refer the following tutorial to see a simple example of SeekBar in android.The tutorial will explain how to adjust the brightness of an imageview in android.

How to adjust the brightness of a image using seekbar in android

 

About the author

Hi guys, i am the author of codesfor. I am a B.Tech graduate currently working as an App developer. Apart from job i am a blogger and a freelancer.

One Comment

  1. Game October 3, 2016 Reply

Add a Comment

Your email address will not be published. Required fields are marked *