Monday, October 16, 2017

Android: Seekbar and Progressbar



Objective: 
The objective of this Android tutorial is to use Seekbar and Progressbar. Refer the screen shots below.

Screenshots:
1. On swipe of Seekbar to the right, the progress bar below also moves along.


Instructions to setup:
1. Git clone the project and you should see the project \5_Seekbar_N_Progressbar downloaded.
2. Now open the project in Android Studio
3. Press the keyboard – Shift + F10 to run the App, select the configured virtual device and click OK.

4. You can now see the output in the Android Emulator.

Source Code Explanation:
1. Activity_main.xml ((under \src\res\layout\):
1. Overall Layout is set as "RelativeLayout"
2. Set the Seekbar component with:
id as "seekBar"
layout_width as “match_parent”
3. Set the Progressbar component with:
id as "progressBar"
layout_width as “match_parent”

2. MainActivity.java:
1. Instantiate ProgressBar, SeekBar, Button by using findViewById() by passing their respective id’s as defined in activity_main.xml
2. Set the max value of Seekbar to 100.
3. Set OnSeekBarChangeListener() function for the button and inside onPressChanged() function set progressBar value (using setProgress() method) to incoming progress value as shown in the code below.

3. strings.xml (under \src\res\values\)
All string values defined

4. colors.xml (under \src\res\values\):
Default standard colors defined


5. styles.xml (under \src\res\values\)
All the default styles defined.


No comments:

Post a Comment