which is best way to implement Android NavigationDrawer Activity in android studio.

                            

Complete idea and concept with explaination of Custom Navigation Drawer each and every step with below diargram. 

 To Implement Android NavigationDrawer Activity we need this below component.

    1)Drawer Layout
    2) Toolbar
    3) Navigation Resource File
    4) Layout Resource File
    5) menu  

Concept :

1) Navigation Drawer

This is a panel that display app's Navigation option from the left  edge of the screen.It is a uniform way to access different pages and information inside our app.                                            

2) Drawer Layout : 

Android Navigation Drawer is a sliding left menu that is used to  display the important links in the application.                            

3) Toolbar : 

Android Toolbar is similar to an ActionBar(now called as App Bars). Toolbar is a Viewgroup that can be placed at anywhere in the Layout. We can easily replace an ActionBar with  Toolbar.


Step By Step Implementation of NavigationDrawer Activity : 

1) New -> project structure -> Dependencies -> click on + sign -> Search design -> Choose latest              version of design - > Press ok.

2) Open style.xml file from res directory.
     After Add theme NoActionBar.

    <style name="Theme.PointsExample" 
          parent="Theme.AppCompat.Light.NoActionBar"/>

3) Change layout main_activity from Constraint layout to Drawer layout.
 
4)  Then add Relative layout -> Toolbar in main_activity.

    <RelativeLayout
    android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:title="Navigation Drawer Demo"
android:titleTextColor="@color/cardview_light_background"
android:background="@color/colorPrimary"
/>
</RelativeLayout>
5) create menu Resource Directory.
   res -> New -> android Resource Directory -> Select Resource directory type -> Give name of Directory(menu) -> Press ok.
6)  After create Menu Resource File. (ex. menuicon.xml)

      res -> New -> Menu Resource File -> Give file_name(menuicon) -> Press ok.

 7) Now Collect icon which you have to need.

      res -> drawable -> New -> Vector assects -> choose icon -> Press ok.
 
 8) Then Open Menu.xml file.and add items which you have to need.
     like ,
     <item android:id="@+id/menu_home"
   android:icon="@drawable/ic_baseline_home_24"
android:title="Home"
/>

<item android:id="@+id/menu_call"
android:icon="@drawable/ic_baseline_call_24"
android:title="Call"
/>

<item android:id="@+id/menu_setting"
android:icon="@drawable/ic_baseline_settings_24"
android:title="Setting"
/>
  9)  Create New layout file (ex.nav_header)

        res -> Layout -> New -> Layout Resouce file ->  Giving Name (nav_header) -> Press ok.

  10)  Take linear vertical layout in nav_header.xml file.
         add content which you want to add.
     like , 
<ImageView
    android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/jp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/cardview_light_background"
android:textSize="30dp"
android:text="Computer Science"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/cardview_light_background"
android:textSize="30dp"
android:text="Android Tutorial"/>
 11)  Now Integrate nav_header layout file and menuicon file into Navigationview.

     <com.google.android.material.navigation.NavigationView
    android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/navmenu"
app:menu="@menu/iconmenu"
app:headerLayout="@layout/nav_header"
android:layout_gravity="start"
/>
12)  Add this code in Main_activity.xml file.





     13) Build and Run Application.

     14) your Android NavigationDrawer Activity is successfully        added in your app.


OUTPUT : 





    The project used in this blog is just for example purpose.
   
 Hope you learned something new today.
 Have a look at our Android tutorials.

 Do share this blog with your fellow developers to spread the knowledge.     You can read more blogs on Android on our blogging website.

  Happy Learning :)

--------------------------------------------------------------------------------------             Share this blog to spread the knowledge

Comments

Popular posts from this blog

🔥 Java Exception and Error Handling

Understanding How OOP Concepts Work with Real-Life Examples

🌿⚙️ Spring Boot Simplified