工具栏隐藏在导航抽屉后面


    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        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">
    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            android:minHeight="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:background="@color/main_color"
            >
        </android.support.v7.widget.Toolbar>

        <FrameLayout
            android:id="@+id/left_drawer"
            android:layout_width="300dp"
            android:layout_height="match_parent"
            android:layout_gravity="left" />
        <FrameLayout
            android:id="@+id/view_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

我正在尝试配置以下组件

工具栏(Appcompat v7 版本(

导航抽屉

但是我的工具栏应该像谷歌保持一样在导航栏后面吗?

把你的Drawer放在主View下面:

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        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">
    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            android:minHeight="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:background="@color/main_color"
            >
        </android.support.v7.widget.Toolbar>
           <FrameLayout
            android:id="@+id/view_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <FrameLayout
            android:id="@+id/left_drawer"
            android:layout_width="300dp"
            android:layout_height="match_parent"
            android:layout_gravity="left" />

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

文件中越下意味着在 Z 轴上越高。

这是最新的解决方案

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:openDrawer="start">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   <!--content_main is my layout you can design your own-->
    <include layout="@layout/content_main" />
    <FrameLayout
        android:id="@+id/content"
        layout="@layout/content_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>

</LinearLayout>

希望对你有帮助

我找到了答案

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/main_color"
            android:minHeight="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
        <FrameLayout
            android:id="@+id/view_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true" />
    </LinearLayout>
       <FrameLayout
        android:id="@+id/left_drawer"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:fitsSystemWindows="true" />

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

最新更新