Quick Contact


    Android SeekBar

    The Android SeekBar is a ProgressBar with a thumb that can be dragged. To advance the music, file download, or other progress, the end user can drag the thum left and right.

    The SeekBar is a search bar.

    The OnSeekBarChangeListener interface has methods for doing even seek bar management.

    AbsSeekBar has two subclasses: SeekBar and RatingBar for Android.

    A ProgressBar is a sort of Android SeekBar. The current value of the progress changes when you touch the thumb on the seekbar and drag it to the right or left. SeekBar is used to forward or reverse music, videos, and other media. The setOnSeekBarChangeListener interface, which has three methods, is utilised.

    onProgressChanged: The progress is changed in this method, and the progress value may then be used in our logic based on the change.

    onStartTrackingTouch: When the user starts dragging, this method is automatically called.

    onStopTrackingTouch: This method is called automatically when the user stops dragging the mouse.

    Android SeekBar Example

    activity_main.xml

    < ?xml version="1.0" encoding="utf-8"?>

    < android.support.constraint.ConstraintLayoutxmlns: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=”example.javatpoint.com.seekbar.MainActivity”>

    < SeekBar

    android:id=”@+id/seekBar”

    android:layout_width=”match_parent”

    android:layout_height=”wrap_content”

    android:layout_marginEnd=”8dp”

    android:layout_marginStart=”8dp”

    android:layout_marginTop=”372dp”

    app:layout_constraintEnd_toEndOf=”parent”

    app:layout_constraintStart_toStartOf=”parent”

    app:layout_constraintTop_toTopOf=”parent” />

    < SeekBar1

    android:id=”@+id/seekBar”

    android:layout_width=”match_parent”

    android:layout_height=”wrap_content”

    android:layout_marginEnd=”28dp”

    android:layout_marginStart=”18dp”

    android:layout_marginTop=”372dp”

    app:layout_constraintEnd_toEndOf=”parent”

    app:layout_constraintStart_toStartOf=”parent”

    app:layout_constraintTop_toTopOf=”parent” />

    < SeekBarDemo

    android:id=”@+id/seekBar”

    android:layout_width=”match_parent”

    android:layout_height=”wrap_content”

    android:layout_marginEnd=”4dp”

    android:layout_marginStart=”16dp”

    android:layout_marginTop=”241dp”

    app:layout_constraintEnd_toEndOf=”child”

    app:layout_constraintStart_toStartOf=”parent”

    app:layout_constraintTop_toTopOf=”parent” />

    < /android.support.constraint.ConstraintLayout>

    < ?xml version="1.0" encoding="utf-8"?>

    < RelativeLayout

    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/message_id”

    android:layout_width=”wrap_content”

    android:layout_height=”wrap_content”

    android:layout_marginTop=”24dp”

    android:text=”geeksforgeeks”

    android:textStyle=”bold”

    android:textSize=”20sp”

    android:layout_gravity=”center”/>

    < SeekBar

    android:id=”@+id/seekbar”

    android:layout_marginTop=”460dp”

    android:layout_width=”fill_parent”

    android:layout_height=”wrap_content”

    android:max=”150″/>

    < /RelativeLayout>

    Enroll Yourself in Live Classes For AngularJS Tutorial.

    Activity class

    package example.Tutorial.ducatindia.com.seekbar;

    import android.support.v7.app.AppCompatActivity;

    import android.os.Bundle;

    import android.widget.SeekBar;

    import android.widget.Toast;

    	public class MainActivity extends AppCompatActivity {  
    	SeekBarseekBar;  
    	    @Override  
    	    protected void onCreate(Bundle savedInstanceState) {  
    	super.onCreate(savedInstanceState);  
    	setContentView(R.layout.activity_main);  
    
    	seekBar=(SeekBar)findViewById(R.id.seekBar);  
    	seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {  
    	            @Override  
    	            public void onProgressChanged(SeekBarseekBar, int progress,  
    	booleanfromUser) {  
    	Toast.makeText(getApplicationContext(),"seekbar progress: "+progress, Toast.LENGTH_SHORT).show();  
    	            }  
    
    	            @Override  
    	            public void onStartTrackingTouch(SeekBar seekBar1) {  
    	Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();  
    	            }  
    	seekBar=(SeekBar)findViewById(R.id.seekBar1);  
    	seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {  
    	            @Override  
    	            public void onProgressChanged(SeekBarseekBar, int progress,  
    	booleanfromUser) {  
    	Toast.makeText(getApplicationContext(),"seekbar progress: "+progress, Toast.LENGTH_SHORT).show();  
    	            }  
    
    	            @Override  
    	            public void onStartTrackingTouch(SeekBarseekBar) {  
    	Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();  
    	            }  
    
    	seekBar=(SeekBar)findViewById(R.id.seekBar);  
    	seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {  
    	            @Override  
    	            public void onProgressChanged(SeekBarseekBar, int progress,  
    	booleanfromUser) {  
    	Toast.makeText(getApplicationContext(),"seekbar progress: "+progress, Toast.LENGTH_SHORT).show();  
    	            }  
    
    	            @Override  
    	            public void onStartTrackingTouch(SeekBarseekBar) {  
    	Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();  
    	            }  
    
    
    	            @Override  
    	            public void onStopTrackingTouch(SeekBarseekBar) {  
    	Toast.makeText(getApplicationContext(),"seekbar touch stopped!", Toast.LENGTH_SHORT).show();  
    	            }  
    	        });  
    	    }  
    	}  
    	
    Outpur: –
    Android SeekBar

    Enroll Yourself in Live Classes For Android training in delhi.

    Copyright 1999- Ducat Creative, All rights reserved.