【问题标题】:How to make navigation drawer apear below actionbar?如何使导航抽屉出现在操作栏下方?
【发布时间】:2017-04-15 19:00:32
【问题描述】:

我知道以前有人问过这个问题,但似乎在较新版本的 AndroidStudio 中发生了一些变化。 Eitehrways,旧的解决方案似乎不起作用,或者我做错了什么。

XML:

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_homescreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/activity_homescreen_drawer" />

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

【问题讨论】:

    标签: java android drawer


    【解决方案1】:

    您的DrawerLayout 在布局中位于应用栏上方,因此它会覆盖它。

    您需要执行以下操作:

    <FrameLayout 
        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"
    ...
    >
    
    <include
            layout="@layout/app_bar_homescreen"
            ...
            />
    
    <android.support.v4.widget.DrawerLayout
        ...>
    
    ... rest of your XML layout
    
    </DrawerLayout>
    </FrameLayout>
    

    这将允许App Bar 被绘制在导航抽屉的“顶部”

    【讨论】:

    • 哦,那行得通。我之前没有尝试的原因是因为 android:fitsSystemWindows 设置为 true!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多