VOOZH about

URL: https://www.geeksforgeeks.org/kotlin/seekbar-in-kotlin/

⇱ SeekBar in Kotlin - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

SeekBar in Kotlin

Last Updated : 12 Jul, 2025

SeekBar in Android is a modified version of progressBar that has a draggable thumb in which a user can drag the thumb back and forth to set the current progress value. We can use SeekBar in our Android Devices like Brightness control, volume control etc. It is one of the important user interface elements 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 usingandroid:minand android:max attributes. respectively.

👁 Dynamic-Seek-Bar


Different Attributes of Android SeekBar Widget

XML AttributesDescription
android:idUsed to uniquely identify the control.
android:thumbUsed to set drawable to be used as a 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 the drawable mode of the progress.
android:backgroundUsed to set the background of the specified view.
android:paddingUsed to set the padding from left, right, top and bottom.

Example of Application Displaying the Value from SeekBar

Step 1: Create New Project

To Create a New Project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Step 2: Modify activity_main.xml file

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

activity_main.xml:

Layout Design:

👁 Layout


Step 3: Make Changes in the Kotlin Code

Changes will be done where we will view the Seekbar using it's id and then display the Progress using Toast.

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

val seek: SeekBar = findViewById(R.id.seekbar)

2. then, setOnSeekBarChangeListener to perform some action on the SeekBar.

seek.setOnSeekBarChangeListener()

3. Display the Toast message when the SeekBar is Updated.

Toast.makeText(this@MainActivity, output , Toast.LENGTH_SHORT).show()

MainActivity.kt:

Output:

Comment
Article Tags:

Explore