Android Discrete SeekBar Tutorial With Example

Hello Readers! In this post, we are going to learn about android discrete seekBar. We will also go through different attributes of discrete seekBar that can be used to customise it.


Tutorialwing Android Discrete SeekBar Output Android Discrete SeekBar Tutorial With Example

Tutorialwing Android Discrete SeekBar Output

Getting Started

Android Discrete SeekBar can be defined as below –

Android discrete seekBar is an extension of ProgressBar that has a draggable thumb. User can drag the thumb back and forth to set the current progress of the seekBar. Discrete SeekBar works for discrete values.

Attributes of Android discrete SeekBar Widget

You can see our post on SeekBar widget to see list of popular attributes of discrete seekbar.

Example of Android discrete SeekBar Widget

At first, we will create an android application. Then, we will use discrete seekBar in the application.

1. Creating New Project

Follow the steps below to create new project. Please ignore the steps if you have already created a new project.

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as DiscreteSeekBar. Then, click next button.
3. Select minimum SDK you need. However, we have selected 17 as minimum SDK. Then, click next button
4. Then, select Empty Activity => click next => click finish.
5. If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit post to create a new project to know steps in detail.

Now, we will modify xml and java file to use seekBar in the application.

2. Modify Values folder

Open res/values/strings.xml file. Then, add below code into it.

	<string name="app_name">DiscreteSeekBar</string>

3. Use android discrete seekBar Widget in xml file

Open res/layout/activity_main.xml file. Then, add below code into it.

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



In activity_main.xml file, we have used android discrete seekBar widget. Note that we have used style=”@style/Widget.AppCompat.SeekBar.Discrete” style to use seekBar widget as discrete seekBar. Also, we have set maximum value for seekBar to 10. Attribute android:progress=”3″ is responsible for setting current progress of the discrete seekBar. Now, we will access this seekBar widget in java file.

4. Access discrete seekBar Widget in java file

Open src/main/java/com.tutorialwing.discreteseekbar/ file. Then, add below code into it.

package com.tutorialwing.discreteseekbar;

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

public class MainActivity extends AppCompatActivity {

	protected void onCreate(Bundle savedInstanceState) {

		SeekBar seekBar = findViewById(;
		if (seekBar != null) {
			seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
				public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
					// Write code to perform some action when progress is changed.

				public void onStartTrackingTouch(SeekBar seekBar) {
					// Write code to perform some action when touch is started.

				public void onStopTrackingTouch(SeekBar seekBar) {
					// Write code to perform some action when touch is stopped.
					Toast.makeText(MainActivity.this, "Current value is " + seekBar.getProgress(), Toast.LENGTH_SHORT).show();

In file, we have accessed seekBar widget. Then, we set listener, seekBarChangeListener, to show a toast message that display current progress of the discrete seekBar.

Since AndroidManifest.xml file is very important in any android application, we will also go through the code inside this file.


Code inside src/main/AndroidManifest.xml file is as below –

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tutorialwing.discreteseekbar"

		<activity android:name=".MainActivity">
				<action android:name="android.intent.action.MAIN"/>

				<category android:name="android.intent.category.LAUNCHER"/>


When you run the program, you will get output as shown above.

That’s end of tutorial on Android Discrete SeekBar Widget.

Leave a Reply