E-Commerce app like Navigation Drawer in Android

In this article, we are going to learn how to create an E-Commerce app like Navigation Drawer in Android.

In the below image you can see that what are we going to build.

Hope so you are interested to know how to make the above E-Commerce app like Navigation Drawer in Android, so now without wasting much time let’s start.

You can also refer our video tutorial for same.

So let’s start with this tutorial :

E-Commerce app like Navigation Drawer in Android

1. Create a new project in Android Studio by navigating to File ⇒ New ⇒ New Project and provide a name to your project. choose Empty activity. By default activity name is MainActivity.java.

2. Now open res => values => styles.xml file and paste the below code to apply some custom styles.

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">#AD000000</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="drawerArrowStyle">@style/DrawerIcon</item>
    </style>
    <style name="TextViewStyle" parent="android:Widget.TextView">
        <item name="android:textColor">#636161</item>
        <item name="android:fontFamily">@font/nunito_regular</item>
        <item name="android:textSize">14sp</item>
    </style>
    <style name="DrawerIcon" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="color">#81000000</item>
    </style>
</resources>

3. Now open res => values => string.xml file and paste the below string resources.

<resources>
    <string name="app_name">E-commerce App Nav Drawer</string>
    <string name="open">Open</string>
    <string name="close">close</string>
</resources>

4. Create a new layout res file by navigating res => layout => New => Layout resource file =>app_bar_main.xml and put the below lines of code to make custom tool bar for app.

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/toolBar"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:background="#fff"
    >
</androidx.appcompat.widget.Toolbar>

5. Now to apply custom font, create a new resource directory by navigating res => New => Android Resource Directory and give the directory name as “font” and select “font” from resource type.

6. Now download this folder and copy all drawable resources from the drawable folder and paste all in res => drawable and copy all fonts from the font folder and paste in the font res => font.

7. Create a new layout res file by navigating res => layout => New => Layout resource file =>header_view.xml and put the below lines of code to make the header view for navigation drawer for the app.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingBottom="26dp"
    android:paddingTop="16dp"
    android:layout_height="wrap_content">
    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:id="@+id/imageView"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="5dp"
        android:src="@drawable/download"
        />
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/TextView"
       android:layout_toRightOf="@+id/imageView"
       android:layout_marginTop="65dp"
       android:layout_marginLeft="10dp"
       android:text="Anamika Rai"
       android:fontFamily="@font/nunito_semibold"
       android:textSize="16sp"
       android:textColor="#1F1E1E"
       />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="65dp"
        android:src="@drawable/backarrow"
        android:tint="#797878"
        />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_marginBottom="30dp"
        android:layout_below="@+id/imageView"
        android:id="@+id/layout"
        android:layout_marginTop="50dp"
        android:layout_height="wrap_content">
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:id="@+id/view1"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/image1"
                android:layout_centerHorizontal="true"
                android:src="@drawable/orders1"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/image1"
                android:id="@+id/text1"
                android:text="My Orders"
                android:textSize="12sp"
                android:fontFamily="@font/nunito_regular"
                android:textColor="#383838"
                android:textAlignment="center"
                />

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:id="@+id/view2"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/image2"
                android:layout_centerHorizontal="true"
                android:src="@drawable/tickets1"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/image2"
                android:id="@+id/text2"
                android:text="My Tickets"
                android:textSize="12sp"
                android:fontFamily="@font/nunito_regular"
                android:textColor="#383838"
                android:textAlignment="center"
                />
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:id="@+id/view3"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/image3"
                android:layout_centerHorizontal="true"
                android:src="@drawable/wallet1"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/image3"
                android:id="@+id/text3"
                android:text="My Wallets"
                android:textSize="12sp"
                android:fontFamily="@font/nunito_regular"
                android:textColor="#383838"
                android:textAlignment="center"
                />
        </RelativeLayout>
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_below="@+id/layout"
        android:background="#7C918B8B"
        />
</RelativeLayout>

8. Now to apply custom font, create a new resource directory by navigating res => New => Android Resource Directory and give the directory name as “menu” and select “menu” from resource type.

9. Now open res => menu => menu.xml file and put the below lines of code to create menu items for navigation drawer.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <group
      android:checkableBehavior="single">
      <item
          android:title="All category"
          android:id="@+id/category"
          android:icon="@drawable/category1"
          />
      <item
          android:title="Dresses"
          android:id="@+id/dress"
          android:icon="@drawable/dress1"
          />
      <item
          android:title="Tops"
          android:id="@+id/top"
          android:icon="@drawable/tops1"
          />
      <item
          android:title="Bottoms"
          android:id="@+id/bottoms"
          android:icon="@drawable/bottoms1"
          />
      <item
          android:title="Shoes"
          android:id="@+id/shoes"
          android:icon="@drawable/shoes1"
          />
      <item
          android:title="Jewelery"
          android:id="@+id/jewelery"
          android:icon="@drawable/jewelery1"
          />
      <item
          android:title="Accessories"
          android:id="@+id/accessories"
          android:icon="@drawable/accessories1"
          />
      <item
          android:title="Sale"
          android:id="@+id/sale"
          android:icon="@drawable/sale1"
          />
  </group>
</menu>

10. Now go to your activity_main.xml file and paste the below lines of code to make Drawer Layout.

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:id="@+id/drawer"
    tools:openDrawer="start"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">
        <include
            layout="@layout/app_bar_main"
            />
    </LinearLayout>
<com.google.android.material.navigation.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/nav_View"
    android:layout_gravity="start"
    app:headerLayout="@layout/header_view"
    app:menu="@menu/menu"
    app:itemHorizontalPadding="40dp"
    app:itemTextAppearance="@style/TextViewStyle"
    />
</androidx.drawerlayout.widget.DrawerLayout>

11. Now open MainActivity.java file and put the below lines of code to add functionality on Drawer Layout.

package com.thecodingshef.e_commerceappnavdrawer;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
import android.os.Bundle;
import com.google.android.material.navigation.NavigationView;

public class MainActivity extends AppCompatActivity {
DrawerLayout drawerLayout;
Toolbar toolbar;
NavigationView navigationView;
ActionBarDrawerToggle toggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerLayout=findViewById(R.id.drawer);
        toolbar=findViewById(R.id.toolBar);
        navigationView=findViewById(R.id.nav_View);
        setSupportActionBar(toolbar);
        toggle=new ActionBarDrawerToggle(this, drawerLayout, toolbar,R.string.open,R.string.close);
        toggle.syncState();
        navigationView.setItemIconTintList(null);
        
    }
}

12. Finally, run the app and you will get the output as shown in the demo image.

If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.

Thank you 🙂 Keep Learning !

Leave a Comment

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