android - 如何使 DrawerLayout 显示在工具栏下方?

标签 android navigation-drawer android-support-library toolbar drawerlayout

如何使抽屉布局位于操作栏/工具栏下方?我正在使用带有新工具栏 View 的 v7:21 应用兼容库。

我看到的例子看起来像

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- drawer view -->
<LinearLayout
    android:layout_width="304dp"
    android:layout_height="match_parent"
    android:layout_gravity="left|start">

    <!-- drawer content -->

</LinearLayout>

<!-- normal content view -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- The toolbar -->
    <android.support.v7.widget.Toolbar  
        android:id="@+id/my_awesome_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <!-- The rest of content view -->

</LinearLayout>  

但是工具栏将被抽屉隐藏,这使得动画汉堡图标(如 v7.ActionBarDrawerToggle)无用,因为它在抽屉下方不可见,但我确实想使用新的 ToolBar View 来支持 Material主题更好。

那么如何实现呢?是否可以将 DrawerLayout 作为非顶级 View ?

最佳答案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <!-- The toolbar -->
    <android.support.v7.widget.Toolbar  
        android:id="@+id/my_awesome_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <!-- drawer view -->
        <LinearLayout
            android:layout_width="304dp"
            android:layout_height="match_parent"
            android:layout_gravity="left|start">

            <!-- drawer content -->

        </LinearLayout>

        <!-- normal content view -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">



            <!-- The rest of content view -->

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

</LinearLayout>  

关于android - 如何使 DrawerLayout 显示在工具栏下方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26464326/

相关文章:

java - 抽屉导航项目图标右侧

java - 努力在 Eclipse 中使用小于 target-sdk 的 min-sdk 编译 Android 应用程序

android 支持 v7 util 缺失

java - 尝试将新的dialogFragment添加到 fragment 上的现有dialogfragmen时,FragmentManager.beginTransaction()在空对象引用上

android - 如何在 Nexus 7 上触发 MediaScan?

android - 编写一个在android中关闭主应用程序时执行的后台程序

java - 如何在Fragment中访问ListView

Android Lollipop 工具栏在打开/关闭抽屉和后退按钮之间切换

android - 抽屉导航 (menudrawer) Android 5 (lollipop) 样式

Android AppCompat 深色主题设置复选框