Android SeekBar is a type of ProgressBar. On touching the thumb on seekbar and dragging it to the right or left, the current value of the progress changes. SeekBar is used for forwarding or backwarding the songs, Video etc. In the setOnSeekBarChangeListener interface is used which provides three methods.
- onProgressChanged: In this method progress is changed and then according to this change the progress value can used in our logic.
- onStartTrackingTouch: In this method when the user has started dragging, then this method will be called automatically.
- onStopTrackingTouch: In this method, when the user stops dragging, then this method will called automatically.
Below are the steps for Creating SeekBar Android Application:
- Step1: Create a new project. After that, you will have java and XML file.
- Step2: Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take. Assigne ID to SeekBar And TextView.
- Step3: Now, open up the activity java file and then define the SeekBar and TextView variable, use findViewById() to get the SeekBar and TextView.
- Step4: Performs seek bar change listener event which is used for getting the progress value. By using this event listener we get the value of Prograss, and the progress is displayed by using a TextView, which will increase the size.
- Step5: Now run the app and touch the thumb and then Drag it, the Text size will increase automatically.
The complete code of MainActivity.java or activity_main.xml of SeekBar is given below:
- Android | Creating a RatingBar
- Creating a Calculator for Android devices
- Android | Creating a Calendar View app
- Android | Creating multiple Screen app
- Android | Creating a Splash Screen
- Android | AdMob Banner Ads for Android Studio
- Android | Android Application File Structure
- Android | AdMob Interstitial Ads for Android Studio
- Android | How to Request permissions in Android Application?
- Android | How to add Radio Buttons in an Android Application?
- Android | Starting with first app/android project
- Android | Running your first Android app
- Android | RecyclerView
- How to use WebView in Android
- How to use CheckBox in Android
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.
Improved By : vartika02