Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

SeekBar in Kotlin

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Android seekBar is a modified version of progressBar that have draggable thumb in which a user can drag the thumb back and forth to set current progress value. We can use seekbar in our android device like Brightness control, volume control etc.

It is one of the important user Interface element which provides the option to select the integer values within the defined range like 1 to 100.

By dragging the thumb in SeekBar, we can slide back and forth to choose a value between minimum and maximum integer value which we defined using android:min and android:max attributes. respectively.

First we create a new project by following the below steps:

  1. Click on File, then New => New Project.
  2. After that include the Kotlin support and click on next.
  3. Select the minimum SDK as per convenience and click next button.
  4. Then select the Empty activity => next => finish.

Different Attributes of Android SeekBar Widget

XML AttributesDescription
android:idUsed to uniquely identify the control.
android:thumbUsed to set drawable to be used as thumb that can be moved back and forth.
android:thumbTintUsed to set tint to apply to the thumb.
android:minUsed to specify the minimum value.
android:maxUsed to specify the maximum value.
android:progressUsed to specify the default progress value between 0 and 100.
android:progressDrawableUsed to specify drawable mode of the progress.
android:backgroundUsed to set background of the specified view.
android:paddingUsed to set the padding from left, right, top and bottom.

Modify activity_main.xml file

Here, we will add the Seekbar widget in LinearLayout and set its attributes like id, margin etc.


<?xml version="1.0" encoding="utf-8"?>
        android:min="0" />

Name of the application specify in the strings.xml file


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

MainActivity.kt file

In the file, we first declare a variable seek and call the seekbar from the xml file using the id.

val seek = findViewById(

then, setOnClickListener to perform some action on the seekBar.


and display the toast message using

   "Progress is: " + seek.progress + "%",


package com.geeksforgeeks.myfirstkotlinapp
import android.os.Bundle
import android.widget.SeekBar
import android.widget.Toast
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        val seek = findViewById<SeekBar>(
        seek?.setOnSeekBarChangeListener(object :
            SeekBar.OnSeekBarChangeListener {
        override fun onProgressChanged(seek: SeekBar,
              progress: Int, fromUser: Boolean) {
          // write custom code for progress is changed
        override fun onStartTrackingTouch(seek: SeekBar) {
            // write custom code for progress is started
         override fun onStopTrackingTouch(seek: SeekBar) {
                // write custom code for progress is stopped
               "Progress is: " + seek.progress + "%",

AndroidManifest.xml file


<?xml version="1.0" encoding="utf-8"?>
    <activity android:name=".MainActivity">
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />

Run as emulator:


My Personal Notes arrow_drop_up
Last Updated : 28 Mar, 2022
Like Article
Save Article
Similar Reads