Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday 23 July 2014

Android: SeekBar Example

1. Create Project named SeekBarExample
2. Create main.xml
<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" >

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_margin="10dp"
        android:progressDrawable="@drawable/styled_progress"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:thumb="@drawable/thumbler_small"
         android:indeterminate="false" />

</RelativeLayout>

3. Create drawable folder in res
4. Create styled_progress in drawable folder
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+android:id/SecondaryProgress"
        android:drawable="@drawable/progress_cyan"/>
    <item
        android:id="@+android:id/progress"
        android:drawable="@drawable/progress_red"/>

</layer-list>

5. Create MainActivity.java
package com.example.seekbarexample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class MainActivity extends Activity {
    SeekBar mybar;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mybar = (SeekBar) findViewById(R.id.seekBar1);
       
        mybar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
           
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
               
                //add here your implementation
            }
           
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

                //add here your implementation
            }
           
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {

                //add here your implementation
            }
        });
    }


}

No comments:

Post a Comment