android - 工具栏将状态栏推开

标签 android xml android-studio toolbar statusbar

我的状态栏出现问题,它被推离了我的工具栏。

我想要的功能是,当用户向下滚动 ListView 时,工具栏会消失在状态栏后面,以便只有选项卡可见,就像在 WhatsApp 和 YouTube 应用程序中一样。

为了达到这个效果或得到这个功能,我使用了这一行:

app:layout_scrollFlags="scroll|enterAlways"

进入我的 android.support.v7.widget.Toolbar,但正如我之前所说,状态栏会被推开。

enter image description here

enter image description here

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

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

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


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

最佳答案

我遇到了同样的问题并设法解决了它。只需删除行:

 android:fitsSystemWindows="true"

来自协调器布局。您可以在 ViewPager 的布局中进一步降低它,但在顶层它似乎会导致该问题。

关于android - 工具栏将状态栏推开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33978134/

相关文章:

java - 创建 Android Intent 并指定目标 Activity 时,这个 ".class"语法是什么?

android - 如何避免在 Android 上自动选择纯 css 下拉菜单中的第一项

java - NsdManager 无法在 android 上注册服务

java - 非法字符 - CTRL-CHAR

java - TabLayout 和 Viewpager - 用图像替换文本

android - java.lang.IllegalArgumentException : This component requires that you specify a valid android:textAppearance attribute

java - 目标是从我的项目中删除文件不起作用

c# - Xml 序列化与 "True"和 "False"

android - 我在哪里可以找到并下载适用于我的 Android 应用程序的 Material Design 图标?

Android Studio 没有生成签名的 APK,尽管它说它成功了