Tuesday, July 21, 2015

202 MyClub Apps Demo How To Create Walkthrough Screen In Android

202 MyClub Apps Demo How To Create Walkthrough Screen In Android
This tutorial demonstrate the steps to create Android Walkthrough Screen Screen based on the Tabbed Activity Templates available in Android Studio.
The Walkthrough basically displays…
...the apps title
...the first point
...the second point
...the third point
and then it loads the Next Activity.
The user can choose to skip the pages by tapping the Floating Action Button.

1) Create a new project using Tabbed Activity

Give a name “Walkthrough” to the activity.

2) Prepare the resources

2.1) Create/Edit the Apps Title image

We can use online services like www.flamingtext.com to create a simple logo for the apps title.
(File: splashtitle_transparent.png)

2.2) Create/Edit the image icons

We can use Image Online Editors like www.pixlr.com/editor to edit images and icons.
This apps uses one background image, three icon images and one title image as shown below. They are provided here so that you can download them as use in your project as well.
Download the zip file above and put the contents under your drawable folder as shown below.

2.3) Define the suitable Color Scheme

Use the Online Tools like www.materialpalette.com to generate a suitable Color Scheme for the apps.
File: res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
   <color name="colorPrimary">#795548</color>
   <color name="colorPrimaryDark">#5D4037</color>
   <color name="colorAccent">#FF5722</color>

3) Edit Layout Files

We want the page to appear full screen.
Therefore, delete the AppBarLayout widget element.
File: res/layout/activity_walkthrough.xml
<?xml version="1.0" encoding="utf-8"?>
           android:layout_height="wrap_content" />
       app:layout_behavior="@string/appbar_scrolling_view_behavior" />
       android:src="@android:drawable/ic_dialog_email" />
Modify the fragment layout so that it contains a background image, ImageView and TextView with additional attributes.
File: res/layout/fragment_walkthrough.xml

4)  Edit the Controller File

Our Controller File, ie Walkthrough.java will implement the following logic…
… ViewPager contains 4 fragment pages
… automatically switches the ViewPager fragment page in 3 seconds duration
… automatically loads the Image and Text according to the fragment page index
… automatically starts the Next Activity after the last fragment page is displayed
… the apps user can skip the fragment pages by tapping the Floating Action Button
We use a runnable class to handle the delay process.
File: Walkthrough.java
package com.notarazi.myclub1;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class Walkthrough extends AppCompatActivity {
    * The {@link android.support.v4.view.PagerAdapter} that will provide
    * fragments for each of the sections. We use a
    * {@link FragmentPagerAdapter} derivative, which will keep every
    * loaded fragment in memory. If this becomes too memory intensive, it
    * may be best to switch to a
    * {@link android.support.v4.app.FragmentStatePagerAdapter}.
   private SectionsPagerAdapter mSectionsPagerAdapter;
    * The {@link ViewPager} that will host the section contents.
   private ViewPager mViewPager;
   private Handler handler;
   protected void onCreate(Bundle savedInstanceState) {
       // Create the adapter that will return a fragment for each of the three
       // primary sections of the activity.
       mSectionsPagerAdapter new SectionsPagerAdapter(getSupportFragmentManager());
       // Set up the ViewPager with the sections adapter.
       mViewPager = (ViewPager) findViewById(R.id.container);
       handler new Handler();
       new Thread(new Task()).start();
       FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
       fab.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
               Intent i = new Intent(Walkthrough.this, NextActivity.class);
   public boolean onCreateOptionsMenu(Menu menu) {
       // Inflate the menu; this adds items to the action bar if it is present.
       getMenuInflater().inflate(R.menu.menu_walkthrough, menu);
       return true;
   public boolean onOptionsItemSelected(MenuItem item) {
       // Handle action bar item clicks here. The action bar will
       // automatically handle clicks on the Home/Up button, so long
       // as you specify a parent activity in AndroidManifest.xml.
       int id = item.getItemId();
       //noinspection SimplifiableIfStatement
       if (id == R.id.action_settings) {
           return true;
       return super.onOptionsItemSelected(item);
    * A placeholder fragment containing a simple view.
   public static class PlaceholderFragment extends Fragment {
        * The fragment argument representing the section number for this
        * fragment.
       private static final String ARG_SECTION_NUMBER "section_number";
       public PlaceholderFragment() {
        * Returns a new instance of this fragment for the given section
        * number.
       public static PlaceholderFragment newInstance(int sectionNumber) {
           PlaceholderFragment fragment = new PlaceholderFragment();
           Bundle args = new Bundle();
           args.putInt(ARG_SECTION_NUMBER, sectionNumber);
           return fragment;
       public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                Bundle savedInstanceState) {
           int pageIndex=0;
           View rootView = inflater.inflate(R.layout.fragment_walkthrough, container,false);
           ImageView ivwWalkthrough=(ImageView)rootView.findViewById(R.id.ivw_walkthrough);
           TextView textView = (TextView) rootView.findViewById(R.id.tvw_walkthrough);
           if (pageIndex==1) {
           }else if (pageIndex==2) {
               textView.setText("...conducive seminar venues...");
           }else if (pageIndex==3) {
               textView.setText("...tasteful delights...");
           }else if (pageIndex==4) {
               textView.setText("...healthy lifestyles...");
           return rootView;
    * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
    * one of the sections/tabs/pages.
   public class SectionsPagerAdapter extends FragmentPagerAdapter {
       public SectionsPagerAdapter(FragmentManager fm) {
       public Fragment getItem(int position) {
           // getItem is called to instantiate the fragment for the given page.
           // Return a PlaceholderFragment (defined as a static inner class below).
           return PlaceholderFragment.newInstance(position + 1);
       public int getCount() {
           // Show 4 total pages.
           return 4;
       public CharSequence getPageTitle(int position) {
           switch (position) {
               case 0:
                   return "SECTION 1";
               case 1:
                   return "SECTION 2";
               case 2:
                   return "SECTION 3";
               case 3:
                   return "SECTION 4";
           return null;
   class Task implements Runnable {
       public void run() {
           mViewPager = (ViewPager) findViewById(R.id.container);
           for (int i = 0; i < 5; i++) {
               final int value = i;
               try {
               } catch (InterruptedException e) {
               handler.post(new Runnable() {
                   public void run() {
           Intent i = new Intent(Walkthrough.this, NextActivity.class);
           //close this activity
We also include an Empty Activity class, ie NextActivity.java to demonstrate the transition from the Walkthrough Activity to the next activity in the apps.




No comments:

Post a Comment