Android Seekbar example tutorial

Use of seekbar and change text size on activity.

SeekBar means a drag n drop customizable bar for android applications to control brightness, font size, screen size. There is already a example available in all android mobile phones of seekbar that is ” Brightness control bar “. So here is the complete step by step tutorial for Android Seekbar example tutorial.

android-project-download-code-button

Android Seekbar example tutorial.

Code for MainActivity.java file.

package com.android_examples.com.seekbar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {

 SeekBar seekBar;
 TextView txtSeekBar;
 int textSize = 3;
 int saveProgress;

 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 txtSeekBar = (TextView)findViewById(R.id.textView1);
 txtSeekBar.setTextScaleX(textSize);
 seekBar = (SeekBar)findViewById(R.id.seekBar1);
 seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
 {
 @Override
 public void onStopTrackingTouch(SeekBar seekBar) 
 {

 }

 @Override
 public void onStartTrackingTouch(SeekBar seekBar) 
 {

 }

 @Override
 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) 
 {
 textSize = textSize + (progress-saveProgress);
 saveProgress = progress;
 txtSeekBar.setTextSize(textSize);
 }
 });

 }
}

Code for activity_main.xml layout file.

<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"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.seekbar.MainActivity" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="31dp"
 android:text="This is Text" />

 <SeekBar
 android:id="@+id/seekBar1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="38dp" />

</RelativeLayout>

Screenshots :

Android Seekbar example tutorial text large on seekbar swipe

Click Here To Download Android Seekbar example tutorial project.

Leave a Reply

Your email address will not be published. Required fields are marked *