Wednesday, 27 January 2016

Android TabLayout example

Write code for   Tab activity   :




(1)write  code for  Main2Activity.java  file:
package tab.om.com.tabactivity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Main2Activity extends TabActivity {

   
public void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
main);

        Resources ressources = getResources();
        TabHost tabHost = getTabHost();

       
// Android tab
       
Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
        TabSpec tabSpecAndroid = tabHost
                .newTabSpec(
"Android")
                .setIndicator(
"", ressources.getDrawable(R.drawable.icon_android_config))
                .setContent(intentAndroid);

       
// Apple tab
       
Intent intentApple = new Intent().setClass(this, AppleActivity.class);
        TabSpec tabSpecApple = tabHost
                .newTabSpec(
"Apple")
                .setIndicator(
"", ressources.getDrawable(R.drawable.icon_apple_config))
                .setContent(intentApple);

       
// Windows tab
       
Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
        TabSpec tabSpecWindows = tabHost
                .newTabSpec(
"Windows")
                .setIndicator(
"", ressources.getDrawable(R.drawable.icon_windows_config))
                .setContent(intentWindows);

       
// Blackberry tab
       
Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
        TabSpec tabSpecBerry = tabHost
                .newTabSpec(
"Berry")
                .setIndicator(
"", ressources.getDrawable(R.drawable.icon_blackberry_config))
                .setContent(intentBerry);

       
// Blackberry tab
       
Intent intentBerry1 = new Intent().setClass(this, BlackBerryActivity.class);
        TabSpec tabSpecBerry1 = tabHost
                .newTabSpec(
"Berry")
                .setIndicator(
"", ressources.getDrawable(R.drawable.icon_blackberry_config))
                .setContent(intentBerry1);

       
// add all tabs
       
tabHost.addTab(tabSpecAndroid);
        tabHost.addTab(tabSpecApple);
        tabHost.addTab(tabSpecWindows);
        tabHost.addTab(tabSpecBerry);
        tabHost.addTab(tabSpecBerry1);

       
//set Windows tab as default (zero based)
        
tabHost.setCurrentTab(2);
    }

}

(2)then    write code for main.xml file  :
<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@android:id/tabhost"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent">

    <LinearLayout

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:padding="5dp">

        <TabWidget

            android:id="@android:id/tabs"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content" />

        <FrameLayout

            android:id="@android:id/tabcontent"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:padding="5dp" />

    </LinearLayout>

</TabHost>
 
(3)now write code for  AndroidActivity.java file:
 
package tab.om.com.tabactivity;



import android.os.Bundle;

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.view.View;



public class AndroidActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.android);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);



        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)

                        .setAction("Action", null).show();

            }

        });

    }



}
 

(4)write   code for    android.xml   file  :
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    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:fitsSystemWindows="true"

    tools:context="tab.om.com.tabactivity.AndroidActivity">



    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_android" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>
 
(5)write   code for content_android.xml   file  :

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/android"

    tools:context="tab.om.com.tabactivity.AndroidActivity">



</RelativeLayout>

(6)Now write code for  AppleActivity.java file:
 
package tab.om.com.tabactivity;



import android.os.Bundle;

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.view.View;



public class AppleActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_apple);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);



        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)

                        .setAction("Action", null).show();

            }

        });

    }



}
 
(7)now  write code for  activity_apple.xml file:
 
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    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:fitsSystemWindows="true"

    tools:context="tab.om.com.tabactivity.AppleActivity">



    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_apple" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>
(8)write code for content_apple.xml file:
 
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    tools:showIn="@layout/activity_apple" tools:context="tab.om.com.tabactivity.AppleActivity">



</RelativeLayout>
 
(9)now write code for  BlackBerryActivity.java file:
 
package tab.om.com.tabactivity;



import android.os.Bundle;

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.view.View;



public class BlackBerryActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_black_berry);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);



        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)

                        .setAction("Action", null).show();

            }

        });

    }



}
 
(10)now write code for activity_black_berry.xml file:
 
 
 
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    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:fitsSystemWindows="true"

    tools:context="tab.om.com.tabactivity.BlackBerryActivity">



    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_black_berry" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>
 
(11)now write code for Content_black_berry.xml file:
 
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    tools:showIn="@layout/activity_black_berry"

    tools:context="tab.om.com.tabactivity.BlackBerryActivity">



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge"

        android:text="Large Text"

        android:id="@+id/textView"

        android:layout_alignParentTop="true"

        android:layout_alignParentRight="true"

        android:layout_alignParentEnd="true"

        android:layout_marginTop="170dp"

        android:layout_alignParentLeft="true"

        android:layout_alignParentStart="true" />

</RelativeLayout>
 
 
(12)now write code for  WindowsActivity.java file:
 
package tab.om.com.tabactivity;



import android.os.Bundle;

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.view.View;



public class WindowsActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_windows);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);



        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)

                        .setAction("Action", null).show();

            }

        });

    }



}
 
(13)now  write code for activity_windows.xml file:
 
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    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:fitsSystemWindows="true"

    tools:context="tab.om.com.tabactivity.WindowsActivity">



    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_windows" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>
 
 
 
(14)now write code for  content_windows.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    tools:showIn="@layout/activity_windows" tools:context="tab.om.com.tabactivity.WindowsActivity">



</RelativeLayout>


Now write code   for xml file which are under  drawable   folder :
(1)icon_android_config.xml :
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- When selected -->

    <item android:drawable="@drawable/ic_tab_android"

          android:state_selected="true" />

    <!-- When not selected -->

    <item android:drawable="@drawable/ic_tab_android" />

</selector>
(2) icon_apple_config.xml
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- When selected -->

    <item android:drawable="@drawable/ic_tab_apple"

          android:state_selected="true" />

    <!-- When not selected -->

    <item android:drawable="@drawable/ic_tab_apple" />

</selector>
(3) ) icon_blackberry_config.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- When selected -->

    <item android:drawable="@drawable/ic_tab_blackberry"

          android:state_selected="true" />

    <!-- When not selected -->

    <item android:drawable="@drawable/ic_tab_blackberry" />

</selector>
(4) icon_windows_config.xml
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- When selected -->

    <item android:drawable="@drawable/ic_tab_windows"

          android:state_selected="true" />

    <!-- When not selected -->

    <item android:drawable="@drawable/ic_tab_windows" />

</selector>

output:






scorlling activity with navigation drawer activity

Scrolling activity with navigation drawer activity:



(1)write  code for MainActivity2.java file:
package mypractice.om.com.mypractice;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class Main2Activity extends AppCompatActivity
       
implements NavigationView.OnNavigationItemSelectedListener {

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main2);
        Toolbar toolbar = (Toolbar) findViewById(R.id.
toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.
fab);
        fab.setOnClickListener(
new View.OnClickListener() {
           
@Override
           
public void onClick(View view) {
                Snackbar.make(view,
"Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction(
"Action", null).show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.
drawer_layout);
        ActionBarDrawerToggle toggle =
new ActionBarDrawerToggle(
               
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.
nav_view);
        navigationView.setNavigationItemSelectedListener(
this);
    }

   
@Override
   
public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.
drawer_layout);
       
if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.
START);
        }
else {
           
super.onBackPressed();
        }
    }

   
@Override
   
public boolean onCreateOptionsMenu(Menu menu) {
       
// Inflate the menu; this adds items to the action bar if it is present.
       
getMenuInflater().inflate(R.menu.main2, menu);
       
return true;
    }

   
@Override
   
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);
    }

   
@SuppressWarnings("StatementWithEmptyBody")
    
@Override
   
public boolean onNavigationItemSelected(MenuItem item) {
       
// Handle navigation view item clicks here.
       
int id = item.getItemId();

       
if (id == R.id.nav_camara) {
           
// Handle the camera action
       
} else if (id == R.id.nav_gallery) {

        }
else if (id == R.id.nav_slideshow) {

        }
else if (id == R.id.nav_manage) {

        }
else if (id == R.id.nav_share) {

        }
else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.
drawer_layout);
        drawer.closeDrawer(GravityCompat.
START);
       
return true;
    }
}

(2)write code for activity_main2.xml file:
<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"

    android:layout_width="match_parent" android:layout_height="match_parent"

    android:fitsSystemWindows="true" tools:openDrawer="start">



    <include layout="@layout/app_bar_main2" android:layout_width="match_parent"

        android:layout_height="match_parent" />



    <android.support.design.widget.NavigationView android:id="@+id/nav_view"

        android:layout_width="wrap_content" android:layout_height="match_parent"

        android:layout_gravity="start" android:fitsSystemWindows="true"

        app:headerLayout="@layout/nav_header_main2" app:menu="@menu/activity_main2_drawer" />



</android.support.v4.widget.DrawerLayout>












(3)write code  app_bar_main2.xml   file :
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    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:fitsSystemWindows="true"

    tools:context="mypractice.om.com.mypractice.Main2Activity">



    <android.support.design.widget.AppBarLayout android:id="@+id/app_bar"

        android:fitsSystemWindows="true" android:layout_height="@dimen/app_bar_height"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout"

            android:fitsSystemWindows="true" android:layout_width="match_parent"

            android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed"

            app:contentScrim="?attr/colorPrimary">



            <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

                android:layout_height="?attr/actionBarSize" android:layout_width="match_parent"

                app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" />



        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_main2" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>

(4)now write code for content_main2.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    tools:showIn="@layout/app_bar_main2" tools:context="mypractice.om.com.mypractice.Main2Activity">



</RelativeLayout>
 
(5)now nav_header_main.xml   file:
 
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height"

    android:background="@drawable/side_nav_bar"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"

    android:gravity="bottom">



    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:paddingTop="@dimen/nav_header_vertical_spacing"

        android:src="@android:drawable/sym_def_app_icon" android:id="@+id/imageView" />



    <TextView android:layout_width="match_parent" android:layout_height="wrap_content"

        android:paddingTop="@dimen/nav_header_vertical_spacing" android:text="Android Studio"

        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />



    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:text="android.studio@android.com" android:id="@+id/textView" />



</LinearLayout>


(6)Now   write   code for   menu/activity_main2_drawer.xml   file  :
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">



    <group android:checkableBehavior="single">

        <item android:id="@+id/nav_camara" android:icon="@android:drawable/ic_menu_camera"

            android:title="Import" />

        <item android:id="@+id/nav_gallery" android:icon="@android:drawable/ic_menu_gallery"

            android:title="Gallery" />

        <item android:id="@+id/nav_slideshow" android:icon="@android:drawable/ic_menu_slideshow"

            android:title="Slideshow" />

        <item android:id="@+id/nav_manage" android:icon="@android:drawable/ic_menu_manage"

            android:title="Tools" />

    </group>



    <item android:title="Communicate">

        <menu>

            <item android:id="@+id/nav_share" android:icon="@android:drawable/ic_menu_share"

                android:title="Share" />

            <item android:id="@+id/nav_send" android:icon="@android:drawable/ic_menu_send"

                android:title="Send" />

        </menu>

    </item>



</menu>
 
 
(7)Write code for  menu/main2.xml file:
 
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/action_settings" android:title="@string/action_settings"

        android:orderInCategory="100" app:showAsAction="never" />

</menu>
 
 
 
 
 
 
(8)write code for    drawable/side_nav_bar.xml   file:
<shape xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle" >

    <gradient

        android:startColor="#81C784"

        android:centerColor="#4CAF50"

        android:endColor="#2E7D32"

        android:type="linear"

        android:angle="135"/>

</shape>
 
 


Recent Posts

Powered by Blogger.

Pages

About Me

My Photo
B.E.(COMPUTER ENGINEER) PHP Web developer & Provide Training for Web Development , Digital Marketing ,Android Mobile Apps Development

 

© 2013 ANDROID TRAINING IN MUMBAI BY OM SIR. All rights resevered. Designed by Templateism

Back To Top