VOOZH about

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

⇱ Dynamic SeekBar in Kotlin - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dynamic 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.

In this article, we will learn how to implement a seekbar programmatically in kotlin.

👁 Dynamic-Seek-Bar


Step by Step Implementation

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

First of all, use LinearLayout and set its attributes like id, layout_width , context etc.

activity_main.xml:


Step 3: Create SeekBar in MainActivity.kt file

Here, we need to declare seek to create SeekBar like this:

val seek = SeekBar(this)

then, we create another variable params and set attributes for that. We will create another variable layout for the main Layout and call from activity_main.xml file using the id main.

val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
params.setMargins(100, 0, 100, 0)
seek.layoutParams = params

val layout: LinearLayout = findViewById(R.id.main)

and add the SeekBar named as seek into the linearLayout using

layout.addView(seek)

MainActivity.kt:

Output:

Comment
Article Tags:

Explore