android - Navigation Drawer 与 Action Bar 略微重叠

标签 android android-actionbar navigation-drawer drawerlayout

我为我的应用制作了一个抽屉导航。我无法将抽屉导航对齐到操作栏下方。这是我的 XML 中的内容:

<android.support.v4.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_layout"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:fitsSystemWindows="true" tools:openDrawer="start">

    <include layout="@layout/app_bar_main" android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView android:id="@+id/nav_view"
        android:layout_width="wrap_content" android:layout_height="match_parent"
        android:layout_gravity="start" android:fitsSystemWindows="true"
        android:layout_marginTop="?attr/actionBarSize"
        app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

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

我已经尝试了 android:layout_marginTop="@dimen/abc_action_bar_default_height_material"android:layout_marginTop="?attr/actionBarSize" 但我仍然得到轻微的重叠可以在下面的照片中看到:

Exhibit A

这就是 app_bar_main.xml 的样子:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

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


</android.support.design.widget.CoordinatorLayout>

最佳答案

更改 NavigationView、DrawerLayout 和 CoordinatorLayout 中的 android:fitsSystemWindows="false"。这同时删除重叠。但是您会发送一个白色的状态栏。

关于android - Navigation Drawer 与 Action Bar 略微重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32998401/

相关文章:

java - 两个ExpandableListView中滚动的同步

全息灯主题中操作栏的 Android 颜色代码

android - Android 图标大小应遵循哪个 Google 文档?

java - Android 抽屉导航中的后退导航不会更改所选项目

android - Flutter 应用程序中的 Kotlin 导致崩溃

Android - ArrayAdapter getCount 总是返回 0

java - 在什么情况下我可以使用选项菜单/操作栏项调用 findViewById?

android - 在 Android 中,使用可绘制资源以编程方式将图标设置为抽屉导航菜单项始终为黑色

android-layout - 影响工具栏样式和定位的抽屉导航片段

android - Gradle 永远下载 "builder-3.1.2.jar"