簡體   English   中英

如何在操作欄下方顯示導航抽屜?

[英]How to make navigation drawer apear below actionbar?

我知道之前曾有人問過這個問題,但似乎在更新版本的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>

您的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繪制在導航抽屜的“頂部”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM