导航抽屉包含操作栏 [英] Navigation Drawer covers Actionbar

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

问题描述

我想要在应用程序中使用导航抽屉,但是我不希望导航抽屉覆盖我的操作栏.操作栏应始终可见.我搜索了互联网,并从stackoverflow和一些博客中获得了一些解决方案,但是都一样.我在使用不带TitleBar或ActionBar的导航抽屉的情况下引用了此解决方案,但仍然一样正如他们在答案中提到的那样,我先给出android.support.v7.widget.Toolbar,然后给出android.support.design.widget.NavigationView. Android Studio设计预览可以正确显示,但在导航抽屉覆盖的实时手机操作栏中.

I wanted Navigation Drawer in my application but I don't want Navigation Drawer to covers my Action Bar. Action bar should be visible always. I searched internet and i got some solution from stackoverflow and some blogs but all are same. I referred this solution Using Navigation Drawer without TitleBar or ActionBar, but still its same. As they mentioned in the answer, i gave android.support.v7.widget.Toolbar first then android.support.design.widget.NavigationView. Android studio design preview is showing correctly but in realtime mobile phone actionbar covered by navigation drawer.

在Android Studio中

In Android Studio

在手机中

,这是 activity_album_dashboard.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".activity.AlbumDashboardActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.AppBarLayout>

        <include layout="@layout/content_album_dashboard" />

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_album_dashboard"
        app:menu="@menu/activity_album_dashboard_drawer" />

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

和nav_header_album_dashboard.xml(我不需要标题,因此只保留空的LinearLayout)

and nav_header_album_dashboard.xml (i don't want header, so just kept empty LinearLayout)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

</LinearLayout>

推荐答案

您需要将工具栏布局放在工具栏之后...只需像这样更改布局...如果您不需要标题,那么为什么要使用任何标头的布局只需从导航视图中删除app:headerLayout="@layout/nav_header_album_dashboard"

You need to put you drawer layout after toolbar ... Just Change your layout like this... and if you don't need header then why using any layout for header just remove app:headerLayout="@layout/nav_header_album_dashboard" from navigation View

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.AlbumDashboardActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start">

    <include layout="@layout/content_album_dashboard" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_album_dashboard"
        app:menu="@menu/activity_album_dashboard_drawer" />

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

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

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