Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java
  • Android
  • Kotlin
  • Flutter
  • Dart
  • Android with Java
  • Android Studio
  • Android Projects
  • Android Interview Questions
Open In App
Next Article:
How to Add RangeSeekbar in Android Using Kotlin?
Next article icon

How to Add RangeSeekbar in Android Using Kotlin?

Last Updated : 12 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

Approach

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 bitbucket can be directly used in the application. 

XML
     allprojects {             repositories {                maven { url 'https://jitpack.io' }            } }          

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. 

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. 

strings.xml
  <string-array name="levelArray">         <item>Lv1</item>         <item>Lv2</item>         <item>Lv3</item>         <item>Lv4</item>         <item>Lv5</item>     </string-array> 

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. 

activity_main.xml
  <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">   <TextView         android:id="@+id/textView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginTop="228dp"         android:textSize="18sp"         android:text="Set difficulty for problem:-"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHorizontal_bias="0.498"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" />      <com.jaygoo.widget.RangeSeekBar         android:id="@+id/range_seekbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:rsb_gravity="bottom"         app:rsb_indicator_background_color="@color/colorProgress"         app:rsb_indicator_height="30dp"         app:rsb_indicator_width="50dp"         app:rsb_mode="single"         app:rsb_progress_color="@color/colorProgress"         app:rsb_step_auto_bonding="true"         app:rsb_step_color="@color/colorProgress"         app:rsb_step_height="10dp"         app:rsb_step_width="5dp"         app:rsb_steps="4"         app:rsb_thumb_drawable="@drawable/ic_baseline_brightness"         app:rsb_tick_mark_layout_gravity="bottom"         app:rsb_tick_mark_mode="other"         app:rsb_tick_mark_text_array="@array/levelArray"         app:rsb_tick_mark_text_margin="20dp"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintLeft_toLeftOf="parent"         app:layout_constraintRight_toRightOf="parent"         app:layout_constraintTop_toTopOf="parent" />  </androidx.constraintlayout.widget.ConstraintLayout> 

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. 

MainActivity.kt
  package org.geeksforgeeks.rangeseekbar  import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Toast import com.jaygoo.widget.OnRangeChangedListener import com.jaygoo.widget.RangeSeekBar import kotlinx.android.synthetic.main.activity_main.*  class MainActivity : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)          //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) {                 Toast.makeText(this@MainActivity,                     leftValue.toString(),Toast.LENGTH_LONG).show()             }              override fun onStartTrackingTouch(view: RangeSeekBar?,                          isLeft: Boolean) {             }              override fun onStopTrackingTouch(view: RangeSeekBar?,                           isLeft: Boolean) {             }         })     } } 

Output:

Refer to the official documentation for more information. 
 


Next Article
How to Add RangeSeekbar in Android Using Kotlin?

M

madhavmaheshwarimm20
Improve
Article Tags :
  • Kotlin
  • Android
  • DSA
  • Kotlin Android
  • Android-Bars

Similar Reads

    How to Send SMS in Android using Kotlin?
    SMS Manager is a class in Android which is used to send the SMS to a specific contact from the android application. We can send text messages, data messages, and multimedia messages using this class. There are different methods that are provided to send different types of messages. In this article,
    4 min read
    How to Create a Splash Screen in Android using Kotlin?
    Android Splash Screen is the first screen visible to the user when the application’s launched. Splash Screen is the user's first experience with the application that's why it is considered to be one of the most vital screens in the application. It is used to display some information about the compan
    3 min read
    How to Add a Range Slider in Android?
    In this article, we will be adding a Range Slider in Android. A Range Slider is used to select a value from a range of numbers. Mostly we see a Range Slider in the audio volume controller and screen brightness adjuster in Android devices. To add a range slider in our activity we will be using a thir
    2 min read
    How to add KenBurns View in Android?
    In this article, we will learn about how to add KenBurns View in android using java. KenBurns View is a useful library that is an extension of ImageView. It creates an immersive experience by animating its Drawable. We can use RandomTransitionGenerator to change the duration and acts as a interpolat
    2 min read
    How to Add Margin in Android using Jetpack Compose?
    In Android, Padding is used to offset the content of the view by a specific number of pixels from either direction, i.e., padding from left, right, top and bottom. Using Padding, we can create multiple borders to a view by applying a combination of multiple padding and border.   So in this article,
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences