获取导航抽屉以在工具栏/操作栏下滑动

时间:2014-11-08 19:55:55

标签: android xml android-actionbar navigation-drawer android-toolbar

我一直在研究我的应用程序的材料设计大修。我很好奇你将如何改变activity_main xml代码以使导航抽屉滑动打开而不覆盖包含那个华丽的新切换按钮的工具栏。任何想法我怎么能这样做?

activity_main:

<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:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

<RelativeLayout
    android:id="@+id/drawerView"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_gravity="start" >

    <ListView
        android:id="@+id/drawerList"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="@drawable/nav_border"
        android:divider="@null" />
</RelativeLayout>
<!--
     <fragment
    android:id="@+id/fragment1"
    android:name="com.shamu11.madlibsportable.MadlibsSelect"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
-->

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

2 个答案:

答案 0 :(得分:3)

我使用以下布局实现了它: Drawer.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.toolbar.Drawer" >

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



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

        <FrameLayout
            android:id="@+id/mainContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </FrameLayout>

        <!-- Nav drawer -->

        <ListView
            android:id="@+id/drawerList"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:background="@android:color/white"
            android:divider="@android:color/white"
            android:dividerHeight="8dp"
            android:drawSelectorOnTop="true"
            android:headerDividersEnabled="true" />
    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app1="http://schemas.android.com/apk/res/com.example.toolbar"
    android:id="@+id/my_awesome_toolbar"
    android:layout_width="fill_parent"
    android:layout_height="75dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app1:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app1:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >

</android.support.v7.widget.Toolbar>

答案 1 :(得分:1)

材料设计指南说导航抽屉应覆盖在一切之上。谷歌与他们的应用程序不一致;但是,我相信他们会将所有应用程序修复为导航抽屉覆盖。

  

导航抽屉横跨屏幕的整个高度,抽屉位于状态栏后面。   http://www.google.com/design/spec/patterns/navigation-drawer.html