gpt4 book ai didi

android - 在 ActionBar 顶部显示 NavigationDrawer

转载 作者:行者123 更新时间:2023-11-30 01:57:24 24 4
gpt4 key购买 nike

我正在使用带有自定义操作栏的 Androidhibe NavigationDrawer 和 SwipeTab,如下所示:

http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

NavigationDrawer 显示在 ViewPager 上方(在 ActionBar 下方),但我希望它显示在 ActionBar 上方。我怎样才能实现这种影响?

最佳答案

您可以使用 Toolbar 而不是 ActionBar 来实现这一点。

Here is a blog post这可能会帮助您切换到工具栏。

MainActivity 的 XML 看起来像这样:

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar"/>

<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.example.app.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />

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

我的工具栏的 XML 如下所示:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"/>

一开始我很纠结,但是一旦我切换到使用工具栏,抽屉导航就会按照我的意愿覆盖工具栏。如果此处的博文和示例代码还不够,请告诉我,我可以继续帮助您解决问题。

关于android - 在 ActionBar 顶部显示 NavigationDrawer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32014509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com