android - 让抽屉导航滑到工具栏/操作栏下方

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

我一直致力于对我的应用进行 Material Design 改造。我很好奇您将如何更改 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>

最佳答案

我使用以下布局实现了它: 抽屉.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>

工具栏.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>

关于android - 让抽屉导航滑到工具栏/操作栏下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26821438/

相关文章:

java - 尝试从另一个类在 MainActivity 中创建实例时出现问题

android - 将图像从 Android 上传到 WebView 中的 ASP.NET MVC Web 应用程序

java - 如何将 xml 节点重命名为 html 标签

android - Android 中固定选项卡内的固定选项卡

java - 我可以使用 C++ 中的 Android NDK 创建位图并将它们快速传递给 Java 吗?

javascript - 读取变量个数的子节点?

c# - 从 XML 文件填充文本框

android - 如何更改操作栏 NAVIGATION_MODE_LIST 中的 'little triangle color'

java - 摆脱 Android 操作栏。

android - 云到设备消息传递 (C2DM) 如何工作?