android - 为什么工具栏在 android 系统状态栏下方(请查看截图)?
问题描述
我收到了一个 android 项目代码,我需要在片段中添加材质工具栏。一切顺利,但我注意到工具栏始终位于屏幕顶部的操作系统状态栏下方,如下图所示:
那么为什么工具栏标题会出现在操作系统状态栏的下方呢?以及如何使状态栏从操作系统状态栏结束的位置开始?
这是片段xml代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/wifi_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/orange_500" />
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/watch" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/downloads_item" />
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/wifi_view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
解决方案
在您的情况下,将以下链接添加到您的父 xml 标记中CoordinatorLayout
。工具栏将出现在状态栏下方。
android:fitsSystemWindows="true"
推荐阅读
- .net-core - 如何使用 .NET Core 识别 swagger doc 中的公共控制器
- powershell - 如何通过 New-CMDetectionClauseWindowsInstaller 将 Productcode 设置为检测方法
- javascript - 尝试将帖子保存到 MongoDB 时出现意外的输入错误结束
- c# - C# 解析 Json 动态对象
- scala - 无法在 Playframework Scala 中使用 JWT cookie 访问 cookie
- c++ - [[noreturn]] 错误处理程序调用必须返回的函数,仍然收到警告
- javascript - 使用 JavaScript 将 HTML 元素重置为默认值
- javascript - JS onClick preventDefault 用于输入
- css - 将变量从 css 导入到 scss
- c++ - 使用 DCMTK 读取 3D Dicom 图像并将其转换为 OpenCV Mat