{"id":1079,"date":"2016-03-19T06:07:04","date_gmt":"2016-03-19T06:07:04","guid":{"rendered":"http:\/\/abhiandroid.com\/ui\/?page_id=1079"},"modified":"2019-06-12T10:34:03","modified_gmt":"2019-06-12T10:34:03","slug":"seekbar","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/ui\/seekbar","title":{"rendered":"SeekBar Tutorial With Example In Android Studio"},"content":{"rendered":"<p>In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1083\" src=\"\/ui\/wp-content\/uploads\/2016\/02\/SeekBar-in-Android.jpg\" alt=\"SeekBar in Android\" width=\"521\" height=\"221\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/02\/SeekBar-in-Android.jpg 521w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/02\/SeekBar-in-Android-300x127.jpg 300w\" sizes=\"auto, (max-width: 521px) 100vw, 521px\" \/><\/p>\n<p>SeekBar is one of the very useful user interface element in Android that allows the selection of integer values using a natural user interface. An example of SeekBar is your device\u2019s brightness control and volume control.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:<\/strong><\/span> Attribute of a SeekBar are same as ProgressBar and the only difference is user determine the progress by moving a slider (thumb) in SeekBar. To add a SeekBar to a layout (XML) file, you can use the\u00a0&lt;SeekBar&gt;\u00a0element.<\/p>\n<p><strong>SeekBar code in XML:<\/strong><\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\" \/&gt;\r\n<\/pre>\n<hr \/>\n<h4><strong>How To Add Listener To Notify The Changes In SeekBar:<\/strong><\/h4>\n<p>SeekBar.OnSeekBarChangeListener is a listener used as a\u00a0callback that notifies client when the progress level of seekbar has been changed. This listener can be used for both user initiated changes (in xml file or java class) as well as for programmatic changes.<\/p>\n<p><strong>seekBarInstanceVariable.setOnSeekBarChangeListener(new\u00a0OnSeekBarChangeListener()\u00a0{&#8230;}<\/strong>\u00a0&#8211; This method is used to notify the user changes\/actions in the SeekBar.<\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #008000;\"><strong>Methods Needs To Be Implemented:<\/strong><\/span><\/span><\/p>\n<p>In Seek bar for getting changes in progress we need to implement three abstract methods. Below is detail description of these three methods:<\/p>\n<p><strong>1. public\u00a0void\u00a0onProgressChanged (SeekBar seekBar,\u00a0int\u00a0progresValue,\u00a0boolean\u00a0fromUser)\u00a0{&#8230;}<\/strong> &#8211;<br \/>\nThis listener method will be invoked if any change is made in the SeekBar.<\/p>\n<p><strong>2. public\u00a0void\u00a0onStartTrackingTouch(SeekBar seekBar)\u00a0{&#8230;}<\/strong> &#8211;<br \/>\nThis listener method will be invoked at the start of user&#8217;s touch event. Whenever a user touch the thumb for dragging this method will automatically called.<\/p>\n<p><strong>3. public\u00a0void\u00a0onStopTrackingTouch(SeekBar seekBar)\u00a0{&#8230;}<\/strong> &#8211;<br \/>\nThis listener method will be invoked at the end of user touch event. Whenever a user stop dragging the thump this method will be automatically called.<\/p>\n<p><span style=\"color: #008000;\"><strong>getMax():<\/strong><\/span><\/p>\n<p>We can get the maximum value of the SeekBar programmatically means in java class. This method returns an integer value. Below code will\u00a0get the maximum value from a Seekbar.<\/p>\n<pre>SeekBar simpleSeekBar = (SeekBar) findViewById(R.id.simpleSeekBar); \/\/ initiate the Seek bar\r\n\r\nint maxValue=simpleSeekBar.getMax(); \/\/ get maximum value of the Seek bar\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>getProgress():<\/strong><\/span><\/p>\n<p>We can get the current progress value from a Seekbar in java class using getProgress() \u00a0method. This method returns an integer value. Below code is used to\u00a0get the current progress value from a Seek bar.<\/p>\n<pre>SeekBar simpleSeekBar=(SeekBar)findViewById(R.id.simpleSeekBar); \/\/ initiate the Seek bar\r\n\r\nint seekBarValue= simpleSeekBar.getProgress(); \/\/ get progress value from the Seek bar\r\n<\/pre>\n<hr \/>\n<h4><strong>Attributes of SeekBar In Android:<\/strong><\/h4>\n<p>Now let\u2019s \u00a0we discuss\u00a0important\u00a0attributes that helps us to configure a SeekBar in xml file (layout).<\/p>\n<p><strong><span style=\"color: #008000;\">1. id:<\/span>\u00a0<\/strong>id attribute uniquely identify SeekBar.<\/p>\n<pre>&lt;SeekBar\r\n    android:id=\"@+id\/simpleSeekBar\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"wrap_content\" \/&gt; &lt;!-- id of a Seek bar used to uniquely identify it--&gt;<\/pre>\n<p><strong><span style=\"color: #008000;\">2. max:<\/span>\u00a0<\/strong>max attribute in SeekBar define the maximum it can take. It must be an integer value like 10, 20, 100, 200 etc. We can set the max value in XML\u00a0file as well as in java class. By default, a SeekBar takes maximum value of 100.<\/p>\n<p>Below we set 150 maximum value for a Seek bar.<\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:max=\"150\"\/&gt;<em>&lt;!-- set 150 maximum value for the progress --&gt;<\/em>\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1087\" src=\"\/ui\/wp-content\/uploads\/2016\/02\/max-in-seekbar-android.jpg\" alt=\"max in seekbar android\" width=\"222\" height=\"174\" \/><\/p>\n<p><strong>Setting max value of\u00a0SeekBar Progress In Java Class :<\/strong><\/p>\n<pre>\/*Add in Oncreate() funtion after setContentView()*\/\r\nSeekBar simpleSeekBar=(SeekBar) findViewById(R.id.<em>simpleSeekBar<\/em>); \/\/ initiate the Seekbar\r\nsimpleSeekBar.setMax(150); \/\/ 150 maximum value for the Seek bar\r\n<\/pre>\n<p><strong><span style=\"color: #008000;\">3. progress:<\/span>\u00a0<\/strong>progress is an attribute of SeekBar used to define the default progress value, between 0 and max. It must be an integer value.<\/p>\n<p>Below we set the 200 max value and then set 50 default progress value.<\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:max=\"200\"\r\nandroid:progress=\"50\"\/&gt;<em>&lt;!-- set 150 maximum value for the progress --&gt;<\/em>\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1088\" src=\"\/ui\/wp-content\/uploads\/2016\/02\/progress-in-SeekBar-Android.jpg\" alt=\"progress in SeekBar Android\" width=\"234\" height=\"169\" \/><\/p>\n<p><strong>Setting progress In Java Class :<\/strong><\/p>\n<pre>SeekBar simpleSeekBar=(ProgressBar) findViewById(R.id.simpleSeekBar); \/\/ initiate the progress bar\r\n\r\nsimpleSeekBar.setMax(200); \/\/ 200 maximum value for the Seek bar\r\n\r\nsimpleSeekBar.setProgress(50); \/\/ 50 default progress value\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>4. progressDrawable:<\/strong><\/span>\u00a0progress drawable attribute is used in Android to set the custom drawable xml for the progress mode of a seekbar. Progress drawable is used when we need to use a custom progress of a seekbar.<\/p>\n<p>Below we set the custom gradient drawable for the progress mode of a Seekbar.<\/p>\n<p><strong>Step 1:<\/strong> Add this code in activity_main.xml or main.xml<\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:max=\"200\"\r\nandroid:progress=\"50\"\r\nandroid:progressDrawable=\"@drawable\/custom_progress\"\/&gt;&lt;!-- set custom progress drawable for the progress --&gt;\r\n<\/pre>\n<p><strong>Step 2:<\/strong> Create a new drawable resource xml in drawable folder and name it custom_progress. Here add the below code which creates gradient effect in seekbar.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;layer-list xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\" &gt;\r\n    &lt;item&gt;\r\n        &lt;shape&gt;\r\n            &lt;gradient\r\n                android:endColor=\"#fff\"\r\n                android:startColor=\"#f00\"\r\n                android:useLevel=\"true\" \/&gt;\r\n        &lt;\/shape&gt;\r\n    &lt;\/item&gt;\r\n\r\n&lt;\/layer-list&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1363\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/progressDrawable-in-SeekBar-Android.gif\" alt=\"progressDrawable in SeekBar Android\" width=\"305\" height=\"270\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>5. indeterminate:<\/strong><\/span>\u00a0indeterminate is an attribute used in android\u00a0to\u00a0enable the indeterminate mode of a seekbar.\u00a0In this mode a seekbar shows a cyclic animation without an indication of progress. This mode is used in application when we don\u2019t know the amount of work has been done. Here\u00a0actual progress\u00a0will be hidden from user.<\/p>\n<p>Below we set the indeterminate to true.<\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:max=\"200\"\r\nandroid:indeterminate=\"true\"\/&gt;&lt;!-- set custom progress drawable for the progress --&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1325 aligncenter\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/indeterminate-in-SeekBar-Android.gif\" alt=\"indeterminate in SeekBar Android\" width=\"137\" height=\"110\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>6. background:<\/strong><\/span>\u00a0background attribute of seekbar is used to set the background. We\u00a0can set a color or a drawable in the background of a Seekbar. We\u00a0can also set the background color in JAVA\u00a0class.<\/p>\n<p>Below we set the green color for the background of a Seek bar.<\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:max=\"200\"\r\nandroid:indeterminate=\"true\"\r\nandroid:background=\"#0F0\"\/&gt;&lt;!-- set green color in the background of seek bar--&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1326\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/background-in-SeekBar-Android.gif\" alt=\"background in SeekBar Android\" width=\"138\" height=\"180\" \/><\/p>\n<p><strong>Setting Background of SeekBar In Java class:<\/strong><\/p>\n<pre>SeekBar simpleSeekBar=(SeekBar)findViewById(R.id.simpleSeekBar); \/\/ initiate the seek bar\r\n\r\nsimpleSeekBar.setBackgroundColor(Color.GREEN); \/\/ green background color for the seek bar<\/pre>\n<p><span style=\"color: #008000;\"><strong>7. padding:<\/strong><\/span>\u00a0padding attribute of seekbar is used to set the padding from left, right, top or bottom.<\/p>\n<ul>\n<li><strong>paddingRight:<\/strong>\u00a0padding right attribute is used to set the padding from the right side of the Seekbar<strong>.<\/strong><\/li>\n<li><strong>paddingLeft:<\/strong> padding left attribute is used to set set the padding from the left side of the Seekbar<strong>.<\/strong><\/li>\n<li><strong>paddingTop: <\/strong>padding top attribute is used to set the padding from the top side of the Seekbar<strong>.<\/strong><\/li>\n<li><strong>paddingBottom: <\/strong>padding bottom attribute is used to set the padding from the bottom side of the Seek bar<strong>.<\/strong><\/li>\n<li><strong>Padding:<\/strong>\u00a0padding attribute is used to set the padding from the all side\u2019s of the Seekbar<strong>.<\/strong><\/li>\n<\/ul>\n<p>Below we set the 20dp padding from the top of the Seek bar.<\/p>\n<pre>&lt;SeekBar\r\n    android:id=\"@+id\/simpleSeekBar\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"wrap_content\"\r\n    android:max=\"200\"\r\n    android:progress=\"150\"\r\n    android:background=\"#34A853\"\r\n    android:paddingTop=\"40dp\"\/&gt;&lt;!-- set  20dp padding from the top of the seek bar--&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1328\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/Padding-in-SeekBar-Android.jpg\" alt=\"Padding in SeekBar Android\" width=\"212\" height=\"202\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>8. thumb:<\/strong><\/span>\u00a0thumb attribute is used in seekbar to draw a thumb on a seekbar. We can use an image or a drawable for the thumb.<\/p>\n<p>Below is an example code in which we set a drawable icon for the thumb of the seekbar.<\/p>\n<p>First download the thumb icon from <a href=\"\/ui\/wp-content\/uploads\/2016\/03\/thumb.png\" target=\"_blank\">here<\/a> and save in drawable folder of your project. You can also click on below icon and then download it:<\/p>\n<p><a href=\"\/ui\/wp-content\/uploads\/2016\/03\/thumb.png\" rel=\"attachment wp-att-1329\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1329\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/thumb.png\" alt=\"thumb icon\" width=\"52\" height=\"48\" \/><\/a><\/p>\n<pre>&lt;SeekBar\r\nandroid:id=\"@+id\/simpleSeekBar\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:max=\"200\"\r\nandroid:progress=\"100\"\r\nandroid:thumb=\"@drawable\/thumb\"\/&gt;&lt;!-- set\u00a0 a thumb drawable icon for the seek bar--&gt;\r\n<\/pre>\n<p><strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1330\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/thumb-in-SeekBar-Android.jpg\" alt=\"thumb in SeekBar Android\" width=\"212\" height=\"190\" \/><\/strong><\/p>\n<hr \/>\n<h4><strong>SeekBar Example In Android Studio:<\/strong><\/h4>\n<p><span style=\"color: #008000;\"><strong>Example 1:<\/strong><\/span> In the below example\u00a0of\u00a0 seekbar in Android we display a simple seekbar by using its different attributes as discussed earlier in this post. We also perform seekbar changed listener event which\u00a0is used to get the changes in the progress of a seek bar.\u00a0After getting changes, the changed value of progress is displayed by using a Toast. Below is the download code, final output and step by step tutorial:<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:<\/strong><\/span> Don&#8217;t miss the 2nd example of Custom SeekBar in Android which is discussed right after this example.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/SeekBarExample\" target=\"_blank\" rel=\"nofollow\">Download Code<\/a><a class=\"help\" title=\"Learn How To Download Code And Import In Android Studio\" href=\"\/androidstudio\/download-code-abhiandroid\" target=\"_blank\" rel=\"nofollow\"> ? <\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1331\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/SeekBar-Example-Android.gif\" alt=\"SeekBar Example Android\" width=\"302\" height=\"471\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>Step 1:<\/strong><\/span> Create a new project and name it <strong>SeekBarExample<\/strong><\/p>\n<p><span style=\"color: #008000;\"><strong>Step 2:<\/strong><\/span> Open res -&gt; layout -&gt;\u00a0<strong>activity_main.xml (or) main.xml<\/strong>\u00a0and add following code:<\/p>\n<p>In this step we open an xml file and add the code for displaying a seekbar by using its different attributes like max, default progress and few more.<\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n    tools:context=\".MainActivity\"&gt;\r\n\r\n    &lt;SeekBar\r\n        android:id=\"@+id\/simpleSeekBar\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_marginTop=\"20dp\"\r\n        android:max=\"200\"\r\n        android:progress=\"60\"\r\n        \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 3:<\/strong><\/span> Open src -&gt; package -&gt;\u00a0<strong>MainActivity.<\/strong><strong>java<\/strong><\/p>\n<p>In this step we open\u00a0MainActivity\u00a0and\u00a0add the code to\u00a0initiate the seekbar and then perform seekbar changed listener event for getting the changes in the progress of the seekbar. By using this event listener we set get the current value of a seekbar and when a user stop the tracking touch, the value of progress is displayed by using a Toast.<\/p>\n<pre>package example.gb.seekbarexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.support.v7.widget.ButtonBarLayout;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\nimport android.view.View;\r\nimport android.widget.SeekBar;\r\nimport android.widget.Button;\r\nimport android.widget.Toast;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    Button submitButton;\r\n    SeekBar simpleSeekBar;\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        \/\/ initiate  views\r\n        simpleSeekBar=(SeekBar)findViewById(R.id.simpleSeekBar);\r\n        \/\/ perform seek bar change listener event used for getting the progress value\r\n        simpleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {\r\n            int progressChangedValue = 0;\r\n\r\n            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {\r\n                progressChangedValue = progress;\r\n            }\r\n\r\n            public void onStartTrackingTouch(SeekBar seekBar) {\r\n                \/\/ TODO Auto-generated method stub\r\n            }\r\n\r\n            public void onStopTrackingTouch(SeekBar seekBar) {\r\n                Toast.makeText(MainActivity.this, \"Seek bar progress is :\" + progressChangedValue,\r\n                        Toast.LENGTH_SHORT).show();\r\n            }\r\n        });\r\n\r\n    }\r\n\r\n    \r\n}<\/pre>\n<hr \/>\n<h4><strong>Custom vertical SeekBar Example In Android Studio:<\/strong><\/h4>\n<p>In the 2nd example of seekbar we displayed a custom vertical seekbar by using its different attributes. Similar to first example we perform seekbar changed listener event which is used in getting the changes done in the progress and then those\u00a0changed value of progress is displayed by using a Toast.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/SeekBarExample\" target=\"_blank\">Download Code<\/a><a class=\"help\" title=\"Learn How To Download Code And Import In Android Studio\" href=\"\/androidstudio\/download-code-abhiandroid\" target=\"_blank\" rel=\"nofollow\"> ? <\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1333\" src=\"\/ui\/wp-content\/uploads\/2016\/03\/custom-seekbar-example-android.gif\" alt=\"custom seekbar example android\" width=\"307\" height=\"472\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>Step 1:<\/strong><\/span> Create a new project and name it <strong>SeekBarExample<\/strong><\/p>\n<p><span style=\"color: #008000;\"><strong>Step 2:<\/strong><\/span> Open res -&gt; layout -&gt; <strong>activity_main.xml (or) main.xml<\/strong>\u00a0and add following code:<\/p>\n<p>In this step we open xml file and add the code for displaying a vertical seekbar by using its different attributes like max, default progress etc. In this xml for displaying a vertical seekbar we used a rotational attribute and set 270 value for that.<\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n    tools:context=\".MainActivity\"&gt;\r\n\r\n    &lt;SeekBar\r\n        android:id=\"@+id\/customSeekBar\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n       android:layout_centerInParent=\"true\"\r\n        android:max=\"200\"\r\n        android:progress=\"40\"\r\n        android:thumb=\"@drawable\/thumb_icon\"\r\n        android:rotation=\"270\"\r\n        android:progressDrawable=\"@drawable\/custom_progress\"\/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong>Step 3:<\/strong>\u00a0 Create an xml file \u00a0in drawable -&gt; custom_progress.xml<\/p>\n<p>In this step we create a custom drawable xml for the seek\u00a0bar. In this xml we create a\u00a0layer list in which we create an item and then set the gradient colors for our custom seek\u00a0bar.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;layer-list xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\r\n    &lt;item&gt;\r\n      \r\n       &lt;shape&gt;\r\n            &lt;gradient android:useLevel=\"true\"\r\n                      android:startColor=\"#560\" \r\n                      android:endColor=\"#454455\"\/&gt;\r\n       &lt;\/shape&gt;\r\n    &lt;\/item&gt;\r\n&lt;\/layer-list&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 4:<\/strong><\/span> Open\u00a0 \u00a0src -&gt; package -&gt; <strong>MainActivity.<\/strong><strong>java<\/strong><\/p>\n<p>In this step we open\u00a0MainActivity\u00a0and here\u00a0we add the code to\u00a0initiate the vertical seekbar and then perform seek bar changed listener event for getting the changes in the progress of the seek bar. By using this event listener we get the current progress value of a seek bar and when a user stop the tracking touch, that value of progress is displayed by using a Toast.<\/p>\n<pre>package example.gb.seekbarexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\nimport android.widget.SeekBar;\r\nimport android.widget.Button;\r\nimport android.widget.Toast;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    Button submitButton;\r\n    SeekBar customSeekBar;\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        \/\/ initiate  views\r\n        customSeekBar =(SeekBar)findViewById(R.id.customSeekBar);\r\n        \/\/ perform seek bar change listener event used for getting the progress value\r\n        customSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {\r\n            int progressChangedValue = 0;\r\n\r\n            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {\r\n                progressChangedValue = progress;\r\n            }\r\n\r\n            public void onStartTrackingTouch(SeekBar seekBar) {\r\n                \/\/ TODO Auto-generated method stub\r\n            }\r\n\r\n            public void onStopTrackingTouch(SeekBar seekBar) {\r\n                Toast.makeText(MainActivity.this, \"Seek bar progress is :\" + progressChangedValue,\r\n                        Toast.LENGTH_SHORT).show();\r\n            }\r\n        });\r\n\r\n    }\r\n\r\n    \r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress. SeekBar is one of the very useful user interface element in Android that allows the selection of integer values using a natural user interface. &hellip; <a href=\"https:\/\/abhiandroid.com\/ui\/seekbar\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">SeekBar Tutorial With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"home.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-1079","page","type-page","status-publish","hentry"],"acf":[],"psp_head":"<title>SeekBar Tutorial With Example In Android Studio \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"Learn seekbar, its methods and attributes used with example in Android. In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/ui\/seekbar\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/comments?post=1079"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1079\/revisions"}],"predecessor-version":[{"id":2797,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1079\/revisions\/2797"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/media?parent=1079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}