Android Seek Bar

Android Development

 Android Seek Bar :-

⇛ layout > .xml file : 

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

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=".First"
android:padding="5dp"
android:orientation="vertical"
android:gravity="center">

<TextView

android:id="@+id/Idtextview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:textColor="#000"
android:textAlignment="center"
android:textAllCaps="false"
android:textStyle="bold"
android:text="I love Programming"/>

<SeekBar

android:id="@+id/Idseekbar1"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="50"
android:padding="10dp"
android:progress="20" />

</LinearLayout>

⇛ java file :

package com.example.dell.seekbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class First extends AppCompatActivity {

private SeekBar seekBar;

private TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);

seekBar = (SeekBar) findViewById(R.id.Idseekbar1);

textView = (TextView) findViewById(R.id.Idtextview1);

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

textView.setTextSize(progress);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
}
}

No comments

Powered by Blogger.