Table of Contents
SeekBar In Android – Introduction
SeekBar In Android –
Create activity_seek_bar File in XML
<?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”
android:layout_marginTop=”20dp”
tools:context=”.seekBarActivity”>
<TextView
android:id=”@+id/seekBarTextview”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentTop=”true”
android:layout_centerHorizontal=”true”
android:text=”Evrything Is Here – EIHeducation”
android:textColor=”@color/teal_700″
android:layout_marginTop=”50dp”/>
<SeekBar
android:id=”@+id/seekBarEIH”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:max=”70″
android:layout_alignParentBottom=”true”
android:layout_alignParentEnd=”true”
android:layout_alignParentRight=”true”
android:layout_marginBottom=”50dp”
android:layout_gravity=”center_horizontal” />
</RelativeLayout>
Create seekBarActivity File in Java
package com.eiheducation.demo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class seekBarActivity extends AppCompatActivity {
TextView seekBarTextview; // declared the TextView objects
SeekBar seekBarEIH; // declared the SeekBar objects
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seek_bar);
// We need to find our elements by IDs
seekBarTextview = findViewById(R.id.seekBarTextview);
seekBarEIH = findViewById(R.id.seekBarEIH);
// Button Code
seekBarEIH.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBarTextview.setTextSize(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
Android Manifest File
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.eiheducation.demo”>
<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/Theme.EIHeducationDemo”>
<activity
android:name=”.MainActivity”
android:label=”@string/app_name”
android:theme=”@style/Theme.EIHeducationDemo.NoActionBar”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity android:name=”.seekBarActivity” />
</application>
</manifest>
SeekBar In Android – Output
Grammarly – Best Free Grammar checker | Spelling checker | Mistake-free document writer for Laptop/Desktop
Online Surveys – Earn Real Money by Online Surveys
Kids Books – 10+ books for Kids | Age group 2 – 10 | Improve knowledge & Productivity