Create Navigation Drawer

Create Navigation Drawer using NavigationView in Android

MainCLASS

package com.example.malik.test;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
public class MainActivity extends AppCompatActivity {

Toolbar toolbar;

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

}

MainXML

<?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:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”com.example.malik.test.MainActivity”
>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical” >
<include
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
layout=”@layout/toolbar_layout”
/>

</LinearLayout>

<android.support.design.widget.NavigationView
android:layout_width=”wrap_content”
android:layout_height=”match_parent”
android:id=”@+id/navigation_view”
android:layout_gravity=”start”
app:menu=”@menu/drawer_menu”
>
</android.support.design.widget.NavigationView>

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

 

drwable_menu Inside Menu

<?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/home_id”
android:icon=”@drawable/pic1″
android:title=”home”></item>
<item
android:id=”@+id/id_message”
android:icon=”@drawable/pic2″
android:title=”Message”></item>

<item
android:id=”@+id/id_setting”
android:icon=”@drawable/ic_info_white_24dp”
android:title=”Settings”></item>
</group>

<item android:title=”Social”>
<menu>

<item
android:id=”@+id/add_to_group”
android:title=”Add to group”
android:icon=”@drawable/ic_info_white_24dp”></item>
<item
android:id=”@+id/id_group”
android:title=”Group”
android:icon=”@drawable/ic_info_white_24dp”></item>
<item
android:id=”@+id/id_share”
android:title=”Share”
android:icon=”@drawable/ic_info_white_24dp”></item>
</menu>
</item>
</menu>

 

toolbar_layout XML

<?xml version=”1.0″ encoding=”utf-8″?>
<android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
android:layout_width=”match_parent” android:layout_height=”wrap_content”
android:id=”@+id/toolbar”
android:background=”?attr/colorPrimaryDark”
android:minHeight=”?attr/actionBarSize”
app:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”

>

</android.support.v7.widget.Toolbar>

Output :

pic

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.