簡體   English   中英

如何從AppCompatActivity的右側打開兩個導航抽屜

[英]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>

這用於MyAccount導航抽屜的內部導航抽屜。我在rightDrawer上具有第一個LoginPage,第二個是Is Account。單擊loginPage抽屜上可用的登錄按鈕時,將調用openInnerDrawer()。

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

兩個導航抽屜會引起很多問題和很多代碼。 我對所有項目都使用材料抽屜庫。 您也可以將其用於兩個導航抽屜,沒有任何問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM