如何在底部栏上重叠导航抽屉?

时间:2019-11-25 12:45:25

标签: android android-studio android-layout

我有一个由4个片段组成的底部栏。片段A,B,C和D。我想要片段A中的导航抽屉,所以我成功实现了。但是问题是,每当我打开抽屉时,底部的栏就位于活动布局的前面,而不是位于该片段中。打开时,如何将底部栏放在导航抽屉后面?

frag_A

   <?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:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<com.google.android.material.navigation.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
     />



<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/toolbar" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="66dp"
        android:background="@color/colorPrimaryDark"
        android:backgroundTint="@color/colorPrimaryDark"
        android:scaleType="center"
        android:src="@drawable/post"
        app:elevation="6dp"
        app:maxImageSize="25dp"
        app:pressedTranslationZ="12dp" />


    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appbar"
        android:background="@color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <include layout="@layout/content_main">

        </include>

    </androidx.core.widget.NestedScrollView>

 </androidx.coordinatorlayout.widget.CoordinatorLayout>


 </androidx.drawerlayout.widget.DrawerLayout>

activity_main

  <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/navigation"
    style="@style/BottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_gravity="bottom"
    android:background="@drawable/rectanle_bg_bottom"
    android:foreground="?attr/selectableItemBackground"
    android:theme="@style/BottomNavigationTheme"
    app:itemBackground="@color/white"
    app:itemIconSize="17dp"
    app:itemIconTint="@drawable/bottom_navigation_selector"
    app:itemTextColor="@color/color_selector"
    app:labelVisibilityMode="labeled"
    />

1 个答案:

答案 0 :(得分:0)

This may helps you

您必须在活动中添加 navdrawer 并通过 ((HomeActivity) getActivity()).unlockDrawer(); 从片段访问它