Modify activity_main.xml file

XML




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">
 
    <SeekBar
            android:id="@+id/seekBar"
            style="@style/Widget.AppCompat.SeekBar.Discrete"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:min="1"
            android:max="10"
            android:progress="7"/>
 
</RelativeLayout>


Note: 

style=”@style/Widget.AppCompat.SeekBar.Discrete”

This style is used to display the seekBar to make it work for discrete values.

Discrete SeekBar in Kotlin

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. 

Similar Reads

Different Attributes of Android Discrete SeekBar

XML Attributes Description 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...

Modify activity_main.xml file

XML          ...

Create SeekBar in MainActivity.kt file

...

AndroidManifest.xml file

Open app/src/main/java/yourPackageName/MainActivity.kt and do the following changes:...

Run as Emulator:

...

Contact Us