在带有标题的操作栏上创建导航抽屉 [英] Creating a navigation drawer over action bar with header

查看:278
本文介绍了在带有标题的操作栏上创建导航抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个翻译应用程序,可以帮助人们学习语言并玩游戏以检查他们的学习情况.该应用程序已经有一个导航抽屉,但它显示在带有项目的操作栏下方.

I have a translation app that helps people to learn a language and play games to check their learning. The app already has a navigation drawer but it appears under the action bar with items.

我想更改导航抽屉以使其显示在操作栏上. 非常希望导航抽屉具有Google Play商店样式标题.

I want to change the navigation drawer to make it appear over the action bar. Very much preferred that the navigation drawer has a google play store style header.

我尝试了许多解决方案,但无法完成.以下是一些示例:

I have tried many solutions but I am not able to get it done. Here are some examples :

[1] 位于顶部ActionBar上的Android导航抽屉 已经尝试了第一和第二解决方案.

[1]Android Navigation Drawer on top ActionBar 1st and 2nd solutions have been tried.

[2] https://www.youtube.com/watch?v = HDYPgS0BM8c& feature = youtu.be 更改styles.xml后已停止,因为操作栏不会消失或出现错误. -是否也可能需要更改color.xml

[2]https://www.youtube.com/watch?v=HDYPgS0BM8c&feature=youtu.be Have stopped after changing styles.xml as the action bar does not disappear or errors appear. - Is it possible that I also have to change color.xml

推荐答案

我将使用新的工具栏而不是ActionBar.请查看此教程: http://www .android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html

I would use the new Toolbar instead of ActionBar. Checkout this tutorial: http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html

重要的部分是您必须将工具栏放在DrawerLayout内,如此处所示(activity_main.xml):

The important part is that you have to put the toolbar inside the DrawerLayout as seen here (activity_main.xml):

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">

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

        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar">
        </include>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World" />

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"

        android:background="#ffffff"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>

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

toolbar.xml:

toolbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/ColorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:elevation="4dp"
    android:paddingTop="@dimen/tool_bar_top_padding">
</android.support.v7.widget.Toolbar>

要使用工具栏,请执行以下操作:

To use the toolbar:

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

这篇关于在带有标题的操作栏上创建导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆