相关疑难解决方法(0)

如何同时使用导航抽屉和底部导航 - 导航架构组件

我有如下屏幕,其中在同一屏幕上包含导航抽屉和底部导航:

应用程序屏幕

我正在使用 Jetpack 导航架构组件。

当前问题和我尝试了什么?

单击第二个和第三个底部导航项会在工具栏上显示后退箭头吗?

尝试过:将与第二和第三底部导航相关的片段设置为顶级目的地

appBarConfig = AppBarConfiguration(setOf(R.layout.fragment_star, R.layout.fragment_stats, R.layout.fragment_user))
Run Code Online (Sandbox Code Playgroud)

代替

appBarConfig = AppBarConfiguration(navController.graph, drawerLayout)
Run Code Online (Sandbox Code Playgroud)

没有工作。

任何帮助高度赞赏!


我的代码如下所示。

活动_main.xml

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">


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

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

            <fragment
                android:id="@+id/navHostFragment"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:defaultNavHost="true"
                app:navGraph="@navigation/nav_graph" />

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottomNav"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="?android:attr/windowBackground"
                app:menu="@menu/menu_bottom" />

        </LinearLayout>

        <!-- gives navDrawer material look-->
        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/nav_drawer_menu"
            app:headerLayout="@layout/nav_header"
            android:fitsSystemWindows="true"
            />
    </androidx.drawerlayout.widget.DrawerLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)

menu_bottom.xml

<?xml version="1.0" encoding="utf-8"?> …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack android-architecture-navigation

21
推荐指数
1
解决办法
2万
查看次数

如何使用同一个应用程序制作导航抽屉和底部导航?

我正在尝试在我的应用程序中使用导航抽屉和底部栏导航。因此我首先创建了导航活动。然后我尝试将底部栏导航添加到同一个活动中。我想开发这样的应用程序:

在Activity.xml 中没有BottomNavigationView,应用程序正在工作。但是当我在Activity.xml 应用程序中添加BottomNavigationView 时崩溃了。logcat 中没有任何显示。我如何在同一个活动中同时使用底部栏导航和导航抽屉,请给我一个简单的例子?谢谢

android

1
推荐指数
1
解决办法
5046
查看次数