【问题标题】:bottom navigation bar along with side navigation bar底部导航栏和侧面导航栏
【发布时间】:2020-07-14 08:39:28
【问题描述】:

我想添加底部导航栏和侧面导航栏,但是当我尝试时,我的工具栏重叠了。我尝试在框架布局下方添加底部导航栏,但没有成功。

提前致谢

<androidx.drawerlayout.widget.DrawerLayout
   
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  >

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:id="@+id/coordinate_layout"
    android:layout_height="match_parent"
    >
<androidx.appcompat.widget.Toolbar
    android:layout_width="match_parent"
    android:id="@+id/toolbar_layout"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/cardview_dark_background"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    />
    
    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
    />
    
</androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.navigation.NavigationView
        android:layout_width="match_parent"
        android:id="@+id/navigation_layout"
        android:layout_height="match_parent"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/menu_drawer"
        android:layout_gravity="start"
        />
</androidx.drawerlayout.widget.DrawerLayout>

【问题讨论】:

    标签: android android-layout bottomnavigationview android-bottomnav


    【解决方案1】:

    将 FrameLayout 和 BottomNavigationView 放在 LinearLayout 中。那应该可以解决它。

    <?xml version="1.0" encoding="utf-8"?>
    <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:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id="@+id/coordinate_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/cardview_dark_background"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark" />
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <FrameLayout
                    android:id="@+id/frame"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />
    
                <com.google.android.material.bottomnavigation.BottomNavigationView
                    android:id="@+id/bottom_navigation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    app:labelVisibilityMode="labeled"
                    app:layout_anchorGravity="bottom"
                    app:menu="@menu/bottom_navigation_menu" />
    
            </LinearLayout>
    
        </androidx.coordinatorlayout.widget.CoordinatorLayout>
    
        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigation_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start" />
    </androidx.drawerlayout.widget.DrawerLayout>
    

    【讨论】: