Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Add RangeSeekbar in Android Using Kotlin?

  • Difficulty Level : Medium
  • Last Updated : 23 Feb, 2021

In this article,  RangeSeekbar is implemented in an application in android. Android Seekbar is a type of progress bar. We can drag the seekbar from left to right and vice versa and hence changes the current progress. Here we use the RangeSeekbar library to add custom seekbar in our app. This library provides us various features like steps, mode, thumbDrawable, etc which makes it way better than seekbar provided by android.


Step 1: Add the support Library in your root build.gradle file (not your module build.gradle file). This library jitpack is a novel package repository. It is made for JVM so that any library which is present in github and bigbucket can be directly used in the application.


allprojects {         
   repositories {         
      maven { url '' }         

Step 2: Add the support library in build.gradle file and add the dependency in the dependencies section. Through this directly RangeSeekbar will be used in the XML.


dependencies {         
         implementation 'com.github.Jay-Goo:RangeSeekBar:v3.0.0'         

Step 3: Create a string-array in strings.xml file present in the values folder.


<string-array name="levelArray">

Step 4: Add the following code in the activity_main.xml file. In this file, seekbar is added to the layout and the important tag like steps, thumbDrawable, mode, and many more are added according to the requirement.


<?xml version="1.0" encoding="utf-8"?>
        android:text="Set difficulty for problem:-"
        app:layout_constraintTop_toTopOf="parent" />
        app:layout_constraintTop_toTopOf="parent" />

Step 5: Add the following code in MainActivity.kt file.  Here setOnRangeChangedListener is added with the seekbar. It is invoked when the user changes the seekbar bar and shows the percentage of progress to which it is changed.


package org.geeksforgeeks.rangeseekbar
import android.os.Bundle
import android.widget.Toast
import com.jaygoo.widget.OnRangeChangedListener
import com.jaygoo.widget.RangeSeekBar
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        //whenever we change progress of seekbar this function 
        //get invoked automatically.
        range_seekbar?.setOnRangeChangedListener(object : 
            OnRangeChangedListener {
            override fun onRangeChanged(
                     rangeSeekBar: RangeSeekBar, leftValue: Float,
                     rightValue: Float, isFromUser: Boolean) {
            override fun onStartTrackingTouch(view: RangeSeekBar?,
                         isLeft: Boolean) {
            override fun onStopTrackingTouch(view: RangeSeekBar?, 
                         isLeft: Boolean) {


Refer to the official documentation for more information. 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!