如何使导航抽屉出现在操作栏下方
How to make the nav-drawer appear below the action bar
我一直在努力让我的导航抽屉出现在操作栏下方。我知道这可能不符合设计指南。
我已经访问了关于该主题的其他几个线程(示例:Navigation drawer below Actionbar),但没有解决我的问题。
经过很多很多的修补,我没有进一步。请帮助解决这个问题。
现状:
https://i.stack.imgur.com/HK1qW.png
layout/activity_spellbook.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.DrawerLayout
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_spellbook"
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="left|start"
android:fitsSystemWindows="false"
app:headerLayout="@layout/nav_header_spellbook"
app:menu="@menu/activity_spellbook_drawer" />
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
只需将应用栏放在 之外DrawerLayout
。
代码:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:fitsSystemWindows="false"
app:headerLayout="@layout/nav_header_spellbook"
app:menu="@menu/activity_spellbook_drawer" />
</android.support.v4.widget.DrawerLayout>
<include
layout="@layout/app_bar_spellbook"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
您必须对下面给出的所有文件进行一些更改:
抽屉布局:
<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="false"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main2"
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:layout_marginTop="?attr/actionBarSize"
app:headerLayout="@layout/nav_header_main2"
app:menu="@menu/activity_main2_drawer" />
</android.support.v4.widget.DrawerLayout>
现在,在出现在 main class(或你写的地方)的 AppBarLayout 中
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
现在,最后在清单文件中将主题添加到您的 activity:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
我一直在努力让我的导航抽屉出现在操作栏下方。我知道这可能不符合设计指南。 我已经访问了关于该主题的其他几个线程(示例:Navigation drawer below Actionbar),但没有解决我的问题。
经过很多很多的修补,我没有进一步。请帮助解决这个问题。
现状: https://i.stack.imgur.com/HK1qW.png
layout/activity_spellbook.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.DrawerLayout
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_spellbook"
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="left|start"
android:fitsSystemWindows="false"
app:headerLayout="@layout/nav_header_spellbook"
app:menu="@menu/activity_spellbook_drawer" />
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
只需将应用栏放在 之外DrawerLayout
。
代码:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:fitsSystemWindows="false"
app:headerLayout="@layout/nav_header_spellbook"
app:menu="@menu/activity_spellbook_drawer" />
</android.support.v4.widget.DrawerLayout>
<include
layout="@layout/app_bar_spellbook"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
您必须对下面给出的所有文件进行一些更改:
抽屉布局:
<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="false"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main2"
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:layout_marginTop="?attr/actionBarSize"
app:headerLayout="@layout/nav_header_main2"
app:menu="@menu/activity_main2_drawer" />
</android.support.v4.widget.DrawerLayout>
现在,在出现在 main class(或你写的地方)的 AppBarLayout 中
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
现在,最后在清单文件中将主题添加到您的 activity:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"