我正在使用带有自定义操作栏的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/