Introduction
Hi guys. Today I explain how to work with the seek bar in Android. To demonstrate how it is used to set the Media Player, Ringer, Alarm, and Notification volume for your device. So you can easily understand using the following instructions.
Step 1
As usual, create a new project file as in the following.

Step 2
Open the "activity_main.xml" file and update it with the following code:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- 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=".MainActivity"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Adjust Media player volume"
- android:textAppearance="?android:attr/textAppearanceLarge" android:padding="10px"/>
- <SeekBar
- android:id="@+id/seekBar1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Adjust Ringer volume"
- android:textAppearance="?android:attr/textAppearanceLarge" android:padding="10px" />
- <SeekBar
- android:id="@+id/seekBar2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Adjust Alarm volume"
- android:textAppearance="?android:attr/textAppearanceLarge" android:padding="10px"/>
- <SeekBar
- android:id="@+id/seekBar3"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Adjust Notification volume"
- android:textAppearance="?android:attr/textAppearanceLarge" android:padding="10px"/>
- <SeekBar
- android:id="@+id/seekBar4"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- </LinearLayout>
Step 3
Open the "MainActivity.java" file and update it with the following code:
- package com.example.androidfourthapp;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }


Ashwani TyagiPosted Apr 11, 2013, 4:15 AM
nice article