相关疑难解决方法(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万
查看次数

如何在同一个应用程序中创建导航抽屉和底栏

我正在创建一个应用程序,我希望在应用程序中有一个导航抽屉和一个底栏.

我认为我的方法很好,但是当我显示它时我可以做导航抽屉,这不是在底栏之上,它落后了,所以我该怎么办呢?我需要底部栏的导航抽屉.

这是我的代码,希望你能帮助我,谢谢你

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent">


    <android.support.v4.widget.DrawerLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

   <include
          layout="@layout/include_list_viewpager" />-

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="300dp"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view" />

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


  <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimaryRed"
        app:itemTextColor="@drawable/nav_item_color_state"
        app:itemIconTint="@drawable/nav_item_color_state"
        app:menu="@menu/navigation" />


</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer bottombar

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

如何使用Android导航组件+BottomNavigationView+NavigationView(Navigation Drawer)

我想知道使用 Navigation Component + BottomNavigationView + NavigationDrawer 的最佳实践是什么。

我已经尝试过谷歌的导航组件高级示例。它适用于多个后堆栈模块。因为它有一个变通方法扩展名。使用这种方法时,每个底部选项卡都有自己的图形,并且图形会随着您选择其中一个选项卡而发生变化。

但是在集成NavigationView的时候,需要提前知道导航图。但在高级示例中,未使用 navGraph 属性,以编程方式为底部导航添加图形。

那么当Bottom Navigation View和Navigation Drawer View一起使用时,我们如何管理图表呢?

android navigation-drawer android-bottom-nav-view android-jetpack android-architecture-navigation

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