导航抽屉覆盖操作栏

2024-01-04

我想在我的应用程序中添加导航抽屉,但是我不希望导航抽屉覆盖我的操作栏。操作栏应该始终可见。我搜索了互联网,从 stackoverflow 和一些博客中得到了一些解决方案,但都是相同的。我参考了这个解决方案使用没有 TitleBar 或 ActionBar 的导航抽屉 https://stackoverflow.com/questions/17735621/using-navigation-drawer-without-titlebar-or-actionbar,但还是一样。正如他们在答案中提到的,我给了android.support.v7.widget.Toolbar首先然后android.support.design.widget.NavigationView。 Android studio 设计预览显示正确,但实时手机操作栏被导航抽屉覆盖。

在 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)

<?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"从导航视图

<?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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

导航抽屉覆盖操作栏 的相关文章

随机推荐

  • 将数据从 C++ 传递到 PHP

    我需要将一个值从 PHP 传递到 C 我想我可以用 PHP 来做passthru 功能 然后我希望 C 对该值执行某些操作并将结果返回给 PHP 这是我无法解决的问题 有谁知道如何将数据从 C 传递到 PHP 我不想使用中间文件 因为我认为
  • 如何使用VBA截取网页截图?

    如何在Excel中使用VBA截取网页截图 问题是 屏幕截图只能通过按键盘的 F6 键来进行 因为 Screenhunter 就是用于此目的的 打印屏幕键被禁用 我使用了以下代码 但意识到无法使用sendkey函数 sub test appl
  • Numpy n 个奇数根(包括负值)

    我想在Python中计算一些数字的n次奇根 Numpy 作为立方根函数 使用该函数我可以计算 x 1 3 x np linspace 100 100 100 np cbrt x gt gt gt array 4 64158883 4 268
  • 如何设置 CultureInfo.InvariantCulture 默认值?

    当我在 C 中有这样一段代码时 double a 0 003 Console WriteLine a 它打印 0 003 如果我还有另一段代码 double a 0 003 Console WriteLine a ToString Cult
  • Mathematica:如何清除符号的缓存,即取消设置无模式的 DownValues

    我是一个糟糕的缓存器 有时 当没有人在看时 我会缓存结果而不包含完整的上下文 如下所示 f x f x x a a 2 f 1 DownValues f Out 2 HoldPattern f 1 gt 3 HoldPattern f x
  • InnoDB Write Log效率太高超过100%(1953.15%)?

    我的服务器上有 MariaDB 具有 16 32 个 CPU 核心 运行 mysqltuner 时一切似乎都正常 除了InnoDB写日志效率 采取1953 15 想知道这正常吗 或者有什么解决方案可以解决这个问题吗 感谢您的建议 InnoD
  • C++——如何重载运算符+=?

    鉴于以下代码片段 class Num public Num int iNumber 0 m iNumber iNumber Num operator const Num rhs this gt m iNumber this gt m iNu
  • 带图像的 Xamarin Forms ListView |文字|时间

    我目前正在使用 xamarin 表单构建一个混合应用程序 我正在尝试构建一个列表视图 显示带有图标和时间戳的错误 这是我想重新制作成 xamarin 形式的概念设计 我用了一个ImageCell尝试让带有一些文本的图标正常工作 但现在我想在
  • MongoDB 中复合 _id 的预期行为?

    我有一个包含 3 个数字属性的复合 id id KeyA 0 KeyBOARD 0 Key 0 相关数据库的 KeyA 有 200 万个相同值 KeyB 有 50 万个相同值的集群 我的理解是 我可以使用以下命令有效地查询 KeyA 和 K
  • 如何在 JupyterLab 中拆分和合并单元格

    In Jupyter实验室 https jupyterlab readthedocs io en latest 给定以下代码单元格 如何将其拆分为多个单元格 同样 给定以下单元格 如何将它们组合成单个单元格 直接使用 JupyterLab
  • opencv颜色检测

    使用opencv 可以在图像或视频帧中检测某种颜色 在一定范围的rgb值之间 吗 您需要定义 RGB 阈值 并处理图像中适合定义的像素 希望不是整个图像 而是较小的感兴趣区域 可能是移动的前景形状 与所讨论的内容类似here http ww
  • Symfony2:验证因第一个错误而停止

    看来 validator gt validate class Symfony2 的验证服务 http symfony com doc current book validation html在 if 返回之前运行所有验证检查 error班级
  • 尽管 rasterized=True,为什么 matplotlib 图文件大小很大?

    一个简单的例子 from matplotlib pyplot import plot savefig from numpy random import randn plot randn 100 randn 100 500 k alpha 0
  • 智能生成String排列组合的方法

    String database a b c 我想根据给定生成以下字符串序列database a b c aa ab ac ba bb bc ca cb cc aaa 我只能想到一个相当 虚拟 的解决方案 public class JavaA
  • 为什么 findstr 不能正确处理大小写(在某些情况下)?

    在 cmd exe 中编写最近的一些脚本时 我需要使用findstr使用正则表达式 客户需要标准 cmd exe 命令 无 GnuWin32 Cygwin VBS 或 Powershell 我只是想知道变量是否包含任何大写字符并尝试使用 g
  • 在 C# 中绘制到新“层”

    构建一个小绘画程序并尝试合并图层的概念 我使用 PictureBox 控件来显示图像 并从 PictureBox 显示的图像中获取 Graphics 对象并绘制到该对象 我的问题是我试图弄清楚如何绘制覆盖在图片框顶部的新 Graphics
  • 我可以以纵向模式播放视频吗?

    谁能解释一下如何在 iPhone 设备上以纵向模式播放视频 如果您提供一些示例代码以供参考 将会非常有帮助 提前致谢 如果您想使用 MPMoviePlayerController 以纵向模式显示电影 那就更好 让您的视频旋转 90 度 以便
  • Oracle 行争用导致高吞吐量 JMS 应用程序中的死锁错误

    Summary 我有兴趣了解高吞吐量应用程序的最佳实践是什么 这些应用程序具有批量消息试图更新同一行并出现 Oracle 死锁错误的情况 我知道您无法避免这些错误 但是如何优雅地从这些错误中恢复 而不被一次又一次发生的此类死锁错误所困扰 D
  • iOS 熄屏后如何继续监控 iBeacon?

    我正在开发一个 iOS 应用程序来监控 iBeacons 它在前景和背景中都表现良好 我还需要它即使在屏幕关闭时也能保持监控 现在我的问题是 当我用肩部按钮关闭屏幕时 NSLog显示iBeacon信号相应地关闭 RSSI 0 beacon
  • 导航抽屉覆盖操作栏

    我想在我的应用程序中添加导航抽屉 但是我不希望导航抽屉覆盖我的操作栏 操作栏应该始终可见 我搜索了互联网 从 stackoverflow 和一些博客中得到了一些解决方案 但都是相同的 我参考了这个解决方案使用没有 TitleBar 或 Ac