Puja Singh
Puja Singh

Reputation: 87

How to Open two Navigation Drawer from Right side on AppCompatActivity

    The above code  is for xml changes.

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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"
tools:context="com.example.ensivo4.mobileapp.SubActivity"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">


<include
    layout="@layout/appbarmain"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_left_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:accessibilityLiveRegion="none">
    <include layout="@layout/navheadermain"/>
</android.support.design.widget.NavigationView>


<android.support.v4.widget.DrawerLayout
    android:id="@+id/inner_drawer_layout"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:layout_gravity="right">

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_right_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     <include layout="@layout/rightdrawer"/>

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

<android.support.design.widget.NavigationView
    android:id="@+id/login_navigation_view"
    android:layout_width="270dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    app:headerLayout="@layout/nav_header_main_myaccount"
    app:menu="@menu/menu_myaccount" />

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

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

This is for Inner Navigation Drawer for MyAccount Navigation Drawer .I have first LoginPage and second Is My Account on rightDrawer .openInnerDrawer() is called while clicking on login button which is available on loginPage drawer.

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);         // this is Main Drawwwer For left and right
    rightNavigationView = (NavigationView) findViewById(R.id.nav_right_view);  //   this is for right Drawer

    private void openInnerDrawer() {
    innerDrawerLayout = (DrawerLayout) findViewById(R.id.inner_drawer_layout);
    innerDrawerLayout.openDrawer(Gravity.RIGHT);
    innerDrawerLayout.setScrimColor(Color.TRANSPARENT);
  //  innerDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    LoginNavigationView =(NavigationView) findViewById(R.id.login_navigation_view);
    LoginNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            int id = item.getItemId();

            if (id == R.id.nav_Orders) {
                Toast.makeText(SubActivity.this, "Right Drawer - Settings", Toast.LENGTH_SHORT).show();
            } else if (id == R.id.nav_Favorite_list) {
                Toast.makeText(SubActivity.this, "Right Drawer - Logout", Toast.LENGTH_SHORT).show();
            } else if (id == R.id.nav_Address) {
                Toast.makeText(SubActivity.this, "Right Drawer - Help", Toast.LENGTH_SHORT).show();
            } else if (id == R.id.nav_track_my_order) {
                Toast.makeText(SubActivity.this, "Right Drawer - About", Toast.LENGTH_SHORT).show();
            }
            else if (id == R.id.nav_coupons) {
                Toast.makeText(SubActivity.this, "Right Drawer - About", Toast.LENGTH_SHORT).show();
            }
            else if (id == R.id.nav_saved_cards) {
                Toast.makeText(SubActivity.this, "Right Drawer - About", Toast.LENGTH_SHORT).show();
            }
            else if (id == R.id.nav_Setting) {
                Toast.makeText(SubActivity.this, "Right Drawer - About", Toast.LENGTH_SHORT).show();
            }
            else if (id == R.id.nav_logout) {
                Toast.makeText(SubActivity.this, "Right Drawer - Logout", Toast.LENGTH_SHORT).show();
                closeInnerDrawer();
            }
            return true;
        }
    });

    //innerDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
}

Upvotes: 1

Views: 858

Answers (1)

Samar Ali
Samar Ali

Reputation: 423

Two navigation drawer will cause a lot of problems and lot of code. I use Material Drawer Library for all my projects. You can also use it for two navigation drawer without any problem

Upvotes: 1

Related Questions