【问题标题】:How to overlap navigation drawer on Bottom bar?如何在底栏上重叠导航抽屉?
【发布时间】:2019-11-25 12:45:25
【问题描述】:

我有一个由 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"
    />

【问题讨论】:

  • 你不能用那个设置真正做到这一点,因为BottomNavigationView 在Activity 的布局中。您可以将DrawerLayout 移动到Activity,然后将其锁定为所有Fragments 之外的所有Fragments。顺便说一句,&lt;NavigationView&gt; 需要在&lt;DrawerLayout&gt; 中最后列出才能正确接收触摸事件。

标签: android android-studio android-layout


【解决方案1】:

This may helps you

你必须在activity中添加navdrawer并通过((HomeActivity) getActivity()).unlockDrawer();从fragment中访问它

【讨论】:

  • 如果您正在回答一个 2 年前的问题,请尝试详细解释您的答案背后的原因,也许还有一些代码,否则这看起来更像是一个快速评论。您可以看到 2 年前的评论中也说过同样的话。
猜你喜欢
  • 2015-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多