抽屉没有覆盖操作栏

drawer not covering actionbar

我想打开一个抽屉,使其覆盖 Actionbar。我尝试使用父线性布局并在其中定义了工具栏和抽屉布局并且工作正常但问题是我看不到那里的菜单项..也就是说我只能通过在屏幕上从左向右滑动来打开抽屉。如果我在线性布局之外定义工具栏而不是菜单显示但操作栏未被抽屉覆盖。如何同时实现两者? 这是我的 xml 文件 Activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/white"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="variofitness.com.schedulekeeper.HomeActivity">
<include
    android:id="@+id/toolbar_actionbar"
    layout="@layout/toolbar_default"
    android:layout_marginTop="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:clickable="true" />

    <fragment
        android:id="@+id/fragment_drawer"
               android:name="variofitness.com.schedulekeeper.Fragments.NavigationDrawerFragment"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>

Please modify your Xml:Put your action bar  inside the drawer or use drawer as parent layout: 
另一个示例代码:
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_all_courses_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >


    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/parent_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.activlearn.ui.AllCoursesActivity">


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

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


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

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

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


    <fragment
        android:name="com.activlearn.fragments.DrawerFragment"
        class="com.activlearn.fragments.DrawerFragment"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        tools:layout="@layout/fragment_drawer" />
</android.support.v4.widget.DrawerLayout>

试试这个方法会有帮助

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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/container_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar" />
        </LinearLayout>

        <FrameLayout
            android:id="@+id/container_body"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />


    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="info.androidhive.materialdesign.activity.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

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

如果您的布局结构正确,这应该可以正常工作。根据 this guidance here:

To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout. Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer.

因此您的 DrawerLayout 应该是根并且有两个直接子级。不过,您需要包含三个元素,因此您需要将工具栏和内容容器组合在一起。在伪代码中,结构如下所示:

<DrawerLayout>

    <LinearLayout> (or other type of layout)
        <Toolbar/>
        <content container/>
    </LinearLayout>

    <Navigation Drawer/>

</DrawerLayout>