Blog purpose for android basic example for android app developer. any query please my contact

Saturday 8 April 2023

android studio seekbr example

 android studio seekbr example


Android SeekBar is a kind of ProgressBar with draggable thumb. The end user can drag the thum left and right to move the progress of song, file download etc.


The SeekBar.OnSeekBarChangeListener interface provides methods to perform even handling for seek bar.


Android SeekBar and RatingBar classes are the sub classes of AbsSeekBar.



1.activity_main.xml:


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

<android.support.constraint.ConstraintLayout 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="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" />  

</android.support.constraint.ConstraintLayout>  



2.MainActivity.java:


import android.support.v7.app.AppCompatActivity;  

import android.os.Bundle;  

import android.widget.SeekBar;  

import android.widget.Toast;  

  

public class MainActivity extends AppCompatActivity {  

    SeekBar seekBar;  

    @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(SeekBar seekBar, int progress,  

                                          boolean fromUser) {  

                Toast.makeText(getApplicationContext(),"seekbar progress: "+progress, Toast.LENGTH_SHORT).show();  

            }  

  

            @Override  

            public void onStartTrackingTouch(SeekBar seekBar) {  

                Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();  

            }  

  

            @Override  

            public void onStopTrackingTouch(SeekBar seekBar) {  

                Toast.makeText(getApplicationContext(),"seekbar touch stopped!", Toast.LENGTH_SHORT).show();  

            }  

        });  

    }  

}  



No comments:

Post a Comment