工具栏后面的导航抽屉 [英] Navigation drawer behind Toolbar
问题描述
我目前正在尝试将导航抽屉放在我的工具栏上,但是我无法弄清楚代码中有什么问题.我已经在网络上进行了很多检查,但是仍然看不到我做错了什么.
I am currently trying to have my navigation drawer going on top of my toolBar but I cannot figure out what's wrong in my code. I checked a lot a lot on the web already but I still can't see what I did wrong.
这是我到目前为止所得到的:
Here is what I got so far:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- the Toolbar -->
<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"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="?attr/colorPrimaryDark">
</android.support.v7.widget.Toolbar>
<!-- Rest of the Content View -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main"
tools:context=".MainActivity">
</RelativeLayout>
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="230dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:fitsSystemWindows="true">
<!-- drawer content -->
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:menu="@menu/drawer_menu"
/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
我已经更改了style.xml,用其他工具上看到的工具栏替换了Actionbar ...
I already changed my style.xml with this to replace Actionbar with Toolbar as I saw on other post...
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="android:windowActionBar">false</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="windowActionModeOverlay">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
推荐答案
发现了它!我所做的实际上一切都很好,问题是当我创建项目时,Android Studio创建了activity_main.xml和content_main.xml ...我所有的代码都位于content_main.xml中,该文件包含在activity_main.xml中,
FOUND IT! all I did was actually good, the problem was that when I created my project Android Studio created activity_main.xml AND content_main.xml...all my code was in content_main.xml which was include in activity_main.xml with:
<include layout="@layout/content_main" />
因此,我删除了activity_main内容,并从content_main.xml复制了我所有的代码,然后删除了其中一个(content_main)和TADAAA ...我只是不知道为什么创建了这两个.xml文件,而不仅仅是一个首先……谜团依然存在
So I erased the activity_main content and copied all my code from content_main.xml and then deleted this one (content_main) and TADAAA... I just actually don't know why it created those two .xml file and not just one at the first place... mystery remains
这篇关于工具栏后面的导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!