Discrete SeekBar is another most common feature that we can see in most of the apps. We can get to see this Discrete SeekBar in most of the music player apps, Rating apps, or for points given. Discrete SeekBar is one of the advanced systems of giving ratings instead of writing. In the previous article, we have implemented Discrete SeekBar in Android without using any 3rd party library. But, in this article, we are going to see how to implement Discrete SeekBar in the Android application. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Applications of Discrete SeekBar
- Discrete SeekBar is used in most music player apps.
- It is mostly used for giving a rating in most e-commerce apps.
- Using Discrete SeekBar in the application improves user experience.
Attributes of Discrete SeekBar
|dsb_max||Used for giving Maximum Value.|
|dsb_min||Used for giving Minimum Value.|
|dsb_indicatorFormatter||String format to apply to the value inside bubble indicator.|
|dsb_indicatorPopupEnabled||Use to show Bubble Indicator.|
|dsb_trackColor||Colour for track drawable.|
|dsb_progressColor||Colour for progress bar and thumb drawable.|
|dsb_rippleColor||Colour for ripple drawer.|
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Add dependency of Discrete SeekBar library in build.gradle file
Then Navigate to Gradle scripts and then to build.gradle(Module) level. Add below line in the build.gradle file in the dependencies section.
now click on Sync now it will sync your all files in build.gradle().
Step 3: Create a new Discrete SeekBar in your activity_main.xml file
Navigate to the app > res > layout to open the activity_main.xml file. Below is the code for the activity_main.xml file.
Step 4: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Now click on the run option it will take some time to build Gradle. After that, you will get output on your device as given below.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.