In Android Discrete SeekBar is just an advancement of progressBar just like the SeekBar, the only difference in SeekBar and discrete SeekBar being that in discrete SeekBar, we can only set the value only to discrete values like 1, 2, 3 and so on.
In this article we will be discussing how to create a SeekBar in Kotlin .
Different Attributes of Android Discrete SeekBar
|android:max||Sets the maximum value|
|android:min||Sets the minimum value|
|android:progress||Specifies the already set progress value|
|android:progressDrawable||Sets drawable of the progress mode.|
|android:thumb||Helps to draw a thumb on seekBar..|
|android:thumbTint||Set blending mode to apply the thumb tint.|
|android:thumbTintMode||Set tint to apply on tick mark drawable.|
|android:tickMarkTint||Set blending mode used to apply the tick mark tint.|
|android:tickMarkTintMode||Set blending mode used to apply the tick mark tint.|
|android:background||Sets background of the view|
|android:id||Sets unique id of the view|
|android:elevation||Sets base z-depth of the view|
First step is to create a new Project in Android Studio. For this follow these steps:
- Click on File, then New and then New Project and give name whatever you like
- Then, select Kotlin language Support and click next button.
- Select minimum SDK, whatever you need
- Select Empty activity and then click finish.
After doing this you will see some directories on the left hand side after your project/gradle is finished loading. It should look like this:
After that, we need to design our layout. For that we need to work with the XML file. Go to app > res > layout and paste the folllowing code:
Modify activity_main.xml file
. This style is used to display the seekBar to make it work for discrete values.
Create SeekBar in MainActivity.kt file
Open app/src/main/java/yourPackageName/MainActivity.kt and do the following changes:
Run as Emulator:
- SeekBar in Kotlin
- Dynamic SeekBar in Kotlin
- Discrete Mathematics | Hasse Diagrams
- Kotlin | Retrieve Collection Parts
- DatePicker in Kotlin
- Kotlin constructor
- Kotlin Recursion
- Kotlin Higher-Order Functions
- Kotlin extension function
- Kotlin annotations
- Kotlin generics
- Kotlin Interfaces
- Kotlin Sealed Classes
- Kotlin Regular Expression
- Kotlin Array
- Kotlin Reflection
- Kotlin list : Arraylist
- Kotlin Collections
- Java Interoperability - Calling Java from Kotlin
- Java Interoperability - Calling Kotlin from Java
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.