我有一个翻译应用程序,可以帮助人们学习语言和玩游戏来检查他们的学习。该应用程序已经有一个导航抽屉,但它出现在带有项目的操作栏下。
我想更改导航抽屉,使其显示在操作栏上。 非常希望导航抽屉具有Google Play商店样式标题。
我尝试了很多解决方案,但我无法完成。以下是一些例子:
[1] Android Navigation Drawer on top ActionBar 第一和第二种解决方案已经尝试过。
[2] https://www.youtube.com/watch?v=HDYPgS0BM8c&feature=youtu.be 更改styles.xml后停止,因为操作栏不会消失或出现错误。 - 我是否有可能更改color.xml
答案 0 :(得分:4)
我会使用新工具栏而不是ActionBar。查看本教程:http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html
重要的是你必须把工具栏放在DrawerLayout中,如下所示(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:
<?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>
使用工具栏:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);