make your seek bar in android

Activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
tools:context="com.example.readerpdf.seekbar.MainActivity">


    <SeekBar
       
android:id="@+id/seekBar"
       
android:layout_width="95sp"
       
android:layout_height="30sp"
       
android:layout_alignParentLeft="true"
       
android:layout_alignParentStart="true"
       
android:layout_alignParentTop="true"
       
android:layout_marginLeft="53dp"
       
android:layout_marginStart="73dp"
       
android:layout_marginTop="54dp" />

    <TextView
       
android:id="@+id/textView"
       
android:layout_width="100sp"
       
android:layout_height="25sp"
       
android:layout_alignParentLeft="true"
       
android:layout_alignParentStart="true"
       
android:layout_below="@+id/seekBar"
       
android:layout_marginLeft="44dp"
       
android:layout_marginStart="44dp"
       
android:layout_marginTop="66dp"
       
android:text="@string/textview_txt"
       
tools:text="    Just Text" />
</android.widget.RelativeLayout>

 





MainActivity.java

package com.example.readerpdf.seekbar;



import android.annotation.SuppressLint;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.SeekBar;

import android.widget.TextView;

import android.widget.Toast;



public class MainActivity extends AppCompatActivity {





    private SeekBar seekBar;

    private TextView textView;



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        setSeekBar();

    }



    @SuppressLint("SetTextI18n")

    public void setSeekBar(){

        seekBar = findViewById(R.id.seekBar);

        textView = findViewById(R.id.textView);

        textView.setText("Covered: "+seekBar.getProgress() + "/" + seekBar.getMax());



        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            Integer progress_value;



            @Override

            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

                progress_value = i;

                textView.setText("Covered: "+ progress_value + "/" + seekBar.getMax());

                Toast.makeText(MainActivity.this, "SeekBar in progress", Toast.LENGTH_SHORT).show();

            }



            @Override

            public void onStartTrackingTouch(SeekBar seekBar) {

                Toast.makeText(MainActivity.this, "SeekBar in StartingTracking", Toast.LENGTH_SHORT).show();



            }



            @Override

            public void onStopTrackingTouch(SeekBar seekBar) {

                textView.setText("Covered: "+ progress_value + "/" + seekBar.getMax());

                Toast.makeText(MainActivity.this, "SeekBar in StopTracking", Toast.LENGTH_SHORT).show();



            }

        });

    }

}




output

Share on Google Plus

About super super

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.