如何在导航抽屉的默认菜单上单击项目时打开另一个菜单

时间:2017-09-14 11:32:26

标签: android android-studio-3.0

让我简单地通过图像来解释。我有一个导航视图,其中包含一个默认菜单,类似于此。

default menu in navigation view

如果我点击一个项目,它应该在抽屉本身打开另一个菜单。

This is the Menu after selecting an item

过去几天我做了一些R& D但是无法理解。因为我想自己做,我只是想要一些提示来做到这一点。

提前谢谢。

1 个答案:

答案 0 :(得分:1)

你应该使用片段来实现这个

点击您的项目

,将FrameLayout替换为您的片段
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/white"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/frmContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>

    </LinearLayout>

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