Android seekBar is an 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:
- Click on File, then New => New Project.
- After that include the Kotlin support and click on next.
- Select the minimum SDK as per convenience and click next button.
- Then select the Empty activity => next => finish.
Here, we create SeekBar programmatically in Kotlin file.
Use activity_main.xml file
First of all, use LinearLayout and set its attributes like id, layout_width , context etc.
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 lParams and set attributes for that. We will create another variable lLayout for LinearLayout and call from activity_main.xml file using the id container.
val lLayout = findViewById
(R.id.container) // Adding SeekBar to LinearLayout lLayout?.addView(seek)
and add the SeekBar named as seek into the linearLayout using
Run as Emulator:
- SeekBar in Kotlin
- Discrete SeekBar in Kotlin
- Dynamic ProgressBar in Kotlin
- Dynamic ScrollView in Kotlin
- Dynamic ImageView in Kotlin
- Dynamic TextView in Kotlin
- Dynamic Button in Kotlin
- Dynamic ImageButton in Kotlin
- Dynamic AutoCompleteTextView in Kotlin
- Dynamic ImageSwitcher in Kotlin
- Dynamic TextClock in Kotlin
- Dynamic Spinner in Kotlin
- Dynamic TextSwitcher in Kotlin
- Dynamic DatePicker in Kotlin
- Dynamic TimePicker in Kotlin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.