如何在AppCompatActivity上从右侧打开两个导航抽屉

时间:2017-02-02 16:09:14

标签: android

    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>

这是针对MyAccount导航抽屉的内部导航抽屉。我有第一个LoginPage和第二个是我的帐户在rightDrawer .openInnerDrawer()被调用,同时点击loginPage抽屉上可用的登录按钮。

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

1 个答案:

答案 0 :(得分:0)

两个导航抽屉会导致很多问题和很多代码。我为我的所有项目使用Material Drawer 库。您也可以将它用于两个导航抽屉而没有任何问题