导航抽屉与Action Bar略微重叠

时间:2015-10-07 17:11:15

标签: 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>

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

将NavigationView的fitSystemWindows属性更改为false。但是design guidelines建议导航抽屉应该出现在ActionBar上方,以便您可能需要重新考虑..

答案 2 :(得分:0)

你可以尝试一下。

 <LinearLayout
    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:orientation="vertical">

    <!-- You could directly use your toolbar instead -->        
    <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.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        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">

            <!-- Put your content here -->

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

        </LinearLayout>

        <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>

相关问题