Table of Contents [hide]
If you follow Android SeekBar example , you will see below screen.
We will customize above SeekBar and it will look as below after customization.
If you want to customize above SeekBar , you can follow below tutorial to create Custom SeekBar it.
Source code:
Step 1 :Creating Project
Create an android application project named “AndroidCustomSeekBarExampleApp”.
Step 2 : Creating Layout
Change res ->layout -> activity_main.xml as below:
If you notice, it has two new attributes android:thumb=”@drawable/thumb” and android:progressDrawable=”@layout/progress_seekbar”. You will understand more about it in further steps.
Step 3: Create thumb and put it in drawable folder :
Step 4 : Creating XML for drawing progress bar :
- Go to res -> layout
- right click on layout
- Click on New -> File.
- Create a file named “progress_seekbar.xml” and paste below code in row_item.xml.
Step 5 : Creating MainActivity
Change src/main/packageName/MainActivity.java as below:
We are getting widget reference from layout file and then using SeekBar’s setOnSeekBarChangeListener method to set listener for our custom seekbar.
Step 6 : Running the app
When you run the app, you will get below screen:
Drag ping circle and use it to set the value for SeekBar.
We are done with Android Custom SeekBar example.
Happy Android Learning !!