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: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.
Different Attributes of Android SeekBar Widget
|android:id||Used to uniquely identify the control.|
|android:thumb||Used to set drawable to be used as thumb that can be moved back and forth.|
|android:thumbTint||Used to set tint to apply to the thumb.|
|android:min||Used to specify the minimum value.|
|android:max||Used to specify the maximum value.|
|android:progress||Used to specify the default progress value between 0 and 100.|
|android:progressDrawable||Used to specify drawable mode of the progress.|
|android:background||Used to set background of the specified view.|
|android:padding||Used 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.
Name of the application specify in the strings.xml 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
Toast.makeText(this@MainActivity, "Progress is: " + seek.progress + "%", Toast.LENGTH_SHORT).show()
Run as emulator:
- Dynamic SeekBar in Kotlin
- Discrete SeekBar in Kotlin
- DatePicker in Kotlin
- Android EditText in Kotlin
- TextView in Kotlin
- ProgressBar in Kotlin
- Dynamic CheckedTextView in Kotlin
- RadioButton in Kotlin
- Dynamic RadioButton in Kotlin
- Switch in Kotlin
- Dynamic Switch in Kotlin
- CheckedTextView in Kotlin
- RatingBar in Kotlin
- Dynamic RatingBar in Kotlin
- Dynamic ImageButton in Kotlin
- ImageButton in Kotlin
- AutoCompleteTextView in Kotlin
- Dynamic AutoCompleteTextView in Kotlin
- Dynamic DatePicker in Kotlin
- 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 firstname.lastname@example.org. 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.