单击工具栏上的图标打开第二个抽屉

时间:2017-10-28 09:40:49

标签: android navigation-drawer toolbar drawerlayout

我的抽屉布局中有2个导航视图。

首先是经典导航。 第二点是显示线性布局,其中包含当前活动(不是导航)的交互式回收视图。

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

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

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/nav_view_upper_rv"
                android:layout_width="match_parent"
                android:layout_height="250dp"/>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/nav_view_lower_rv"
                android:layout_width="match_parent"
                android:layout_height="250dp"/>

        </LinearLayout>

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

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

第二个抽屉我只能通过滑动来打开,但我也想通过点击工具栏上的另一个(非汉堡包)图标来打开它。 这样做我想要结合预设导航的所有优点和两个抽屉的材料设计中的自定义。

有可能吗? 如果我做错了,请告诉我正确的解决方案

附近有问题: Two Navigation Drawer on same Activity

How to open Navigation Drawer with no actionbar, open with just a button

How to open Side bar on icon click in Android?

0 个答案:

没有答案