首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在带有标题的操作栏上创建导航抽屉

在带有标题的操作栏上创建导航抽屉
EN

Stack Overflow用户
提问于 2015-06-23 17:04:42
回答 1查看 9.3K关注 0票数 1

我有一个翻译应用程序,可以帮助人们学习一种语言,并玩游戏来检查他们的学习情况。这个应用程序已经有了一个导航抽屉,但它出现在带有项目的操作栏下面。

我想更改导航抽屉,使其显示在操作栏的上方。非常希望在导航抽屉中有一个google play商店样式标题。

我试过很多解决方案,但都不能成功。下面是一些示例:

已经尝试了1 1和2解决方案。

更改styles.xml后2已停止,因为操作栏未消失或出现错误。-是否有可能我还必须更改color.xml

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-23 17:09:44

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

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

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<?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>

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

代码语言:javascript
复制
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30998414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档