如何使导航抽屉出现在操作栏下方?
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
绘制导航抽屉 "on top"
我知道之前有人问过这个问题,但在较新版本的 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
绘制导航抽屉 "on top"