工具栏将状态栏推开

时间:2015-11-29 00:43:49

标签: 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>

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,并设法修复它。只需删除该行:

 android:fitsSystemWindows="true"
来自协调器布局的

。您可以在ViewPager中进一步向下布局,但在顶层它似乎会导致该问题。