繁体   English   中英

如何使用导航抽屉的底部导航

[英]How to use Bottom Navigation with Navigation Drawer

我正在尝试添加带有底部导航视图的导航抽屉。 我有所有底部导航视图片段的全屏活动。 我的应用程序图标左上方。 我想在用户点击该图标时打开导航抽屉。 那么我该如何实现呢?

我尝试使用DrawerLayout。 但它包括工具栏。 我尝试在点击导航抽屉项目时打开新活动,但它给出了IllegleStateException。

我在下面分享了以下代码。 您必须在工具栏中放置导航抽屉的汉堡菜单图标,并在DrawerLayout中放置一个NavigationView,其中有一个子程序(ListView,RecyclerView,ExpandableListView等)以编程方式填充,或者您只需在NavigationView中设置静态项目即可NavigationView中的菜单。 希望有所帮助。 如果您有任何疑问,请询问。

<androidx.drawerlayout.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">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorActivityBackground"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:layoutDirection="locale"
        android:orientation="vertical"
        android:textDirection="locale">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/topbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                app:contentInsetEnd="0dp"
                app:contentInsetLeft="0dp"
                app:contentInsetRight="0dp"
                app:contentInsetStart="0dp"/>
        </RelativeLayout>
    </FrameLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:maxWidth="320dp">

        <ExpandableListView
            android:id="@+id/navList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:background="@color/white"
            android:groupIndicator="@null" />

    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM