---
title: "SeekBar in Android"  
description: "Android provides SeekBar control which is similar to progress bar except it has to drag and drop functionality by which user can adjust the functional"  
author: "Nitish Kesarwani"  
published: 2018-01-02  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/12754/seekbar-in-android  
category: "android apps"  
tags: ["xml", "android", "java", "android styles"]  
reading_time: 4 minutes  

---

# SeekBar in Android

##### Description

Android provides SeekBar control which is similar to [progress bar](https://www.mindstick.com/articles/12747/android-progress-bar) except it has to [drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) by which user can adjust the functionality of the control. It is a part of widget category. [Android studio](https://www.mindstick.com/blog/10942/android-studio-vs-eclipse) provides a function to drag and drop the control in design [interface](https://www.mindstick.com/articles/12036/interface-in-c-sharp) so that developer can develop the app in quickly. We can use this control from palette bar.

Controls like TextView and Seekbar are introduced in the program. These [components](https://www.mindstick.com/blog/74096/understanding-the-role-of-some-integral-ac-components) are easily dragged and drop from palette toolbox and declare into the Main_Activity.xml. When controls are declared then you switch to Main_Activity.java file which contains control functionality performance. It is available in music player, volume adjustable interface and screen setting. SeekBar has OnprogressChanged, OnStartTrackingTouch and OnStopTrackingTouch method which is used check and tracks the user response.

##### Attributes

• **android:inderminate :** it defines an indeterminate state of the seekbar. It means progress is not be identified.

• **android:drawable :** we can define custom drawable screen for seekbar in [xml file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) inside drawable directory.

• **android:thumb :** Here, I have define custom drawable thumb in seekbar separately in xml file inside drawable directory.

• **android:max:** In this attribute, we can define the [maximum value](https://answers.mindstick.com/qa/38240/according-to-recent-rbi-directives-to-banks-how-many-pieces-of-soiled-currency-notes-with-a-maximum-value-of-rs-5-000-can-be-exchanged-at-banks-free-of-charge) of seekbar.

• **Android:progress :** This attribute describe the default progress value of Seekbar.

• **Android:rotation :** It is used to rotate the screen from the [default value](https://www.mindstick.com/forum/23023/default-value-when-using-singleordefault).

##### Methods

• **Seekbar.setSeekBarChangeListener(new SeekBarChangeListener()) :** it notifies and check the [current status](https://yourviews.mindstick.com/story/2866/current-status-of-glacier) of seekbar.

• **OnProgressChange(SeekBar sk,int progress,booleab fromUser) :** It analyse the status of seekbar from initial level to current level.

• **onStartTrackingTouch(seekbar):-**This method tell about the gesture event that handling the seekbar thumb is started by user.

• **onStopTrackingTouch(seekbar):-**This method tell about the gesture event that handling the seekbar thumb is reached to maximum limit.

• **setProgess():** it defines default value of seekbar.

• **setMax()** : It sets the maximum limit of seekbar

##### Android_mainfest.xml

```
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.mapsample.msclient009.seekbar">    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme">        <activity android:name=".MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>
```

##### Main_Activity.xml

```
<?xml version="1.0" encoding="utf-8"?><LinearLayout    android:orientation="vertical"    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.mapsample.msclient009.seekbar.MainActivity">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical">    <TextView        android:id="@+id/tV"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_weight="1"        android:text="SeekBar is Running"        android:background="#199119"        android:gravity="center"        android:textSize="25dp"        android:textColor="#F9F9F9"/>    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="vertical"        android:layout_marginTop="20dp">    <SeekBar        android:id="@+id/seekbar"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_weight="1"        android:max=”100”        android:progress=”0”        android:progressDrawable=”@drawable/progress”        android:thumb =”@drawable/thumbnail”        />    </LinearLayout></LinearLayout>
```

##### Progress.xml

```
<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval" >    <gradient        android:angle="270"        android:endColor="@color/blue"        android:startColor="@color/black" />    <size        android:height="35dp"        android:width="35dp" /></shape>
```

##### Thumbnail.xml

```
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item        android:id="@android:id/background"        android:drawable="@drawable/seekbar"/>    <item android:id="@android:id/progress">        <clip android:drawable="@color/Yellow" />    </item></layer-list>
```

##### Main_Activity.java

```
package com.mapsample.msclient009.seekbar;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.SeekBar;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {TextView tv;SeekBar sb;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate ( savedInstanceState );        setContentView ( R.layout.activity_main );        tv =(TextView)findViewById ( R.id.tV );        sb =(SeekBar)findViewById ( R.id.seekbar );        sb.setOnSeekBarChangeListener ( this );    }    public void onProgressChanged(SeekBar sb0,int p,boolean status)    { if(p>10 && status==true) {        onStartTrackingTouch ( sb0 );        Toast.makeText ( getApplicationContext ( ), "progress is implemented"+p, Toast.LENGTH_LONG ).show ( );    }else {onStopTrackingTouch ( sb0 );}    }    public void onStartTrackingTouch(SeekBar sb1)    { Toast.makeText ( getApplicationContext (),"start Touching is Enabled",Toast.LENGTH_LONG ).show ();    }    public void onStopTrackingTouch(SeekBar sb2)    {        Toast.makeText ( getApplicationContext (),"Stop Seekbar is Enabled",Toast.LENGTH_LONG ).show ();    }}
```

![SeekBar in Android](https://www.mindstick.com/mindstickarticle/32a6915e-a249-4306-8123-5ee60499f4b7/images/bac7a01d-2b73-48d5-9156-83ce36c56879.png) ![SeekBar in Android](https://www.mindstick.com/mindstickarticle/32a6915e-a249-4306-8123-5ee60499f4b7/images/45853945-61e3-483a-8980-f2f4fc92c2b6.png)\

---

Original Source: https://www.mindstick.com/articles/12754/seekbar-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
