Android状态栏以协调器布局向上滚动,而状态图标与工具栏标题重叠 [英] Android status bar scrolling up with coordinator layout, leaving status icons overlapping toolbar title

查看:62
本文介绍了Android状态栏以协调器布局向上滚动,而状态图标与工具栏标题重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用包含AppBarLayout(持有ToolBar和TabLayout)和ViewPager(持有片段)的Coordinator Layout作为子项时遇到问题.我希望在向下滚动时隐藏顶部栏,而在向上滚动时显示顶部栏.但是,当我向下滚动时,状态栏也会向上滚动,而顶部栏位于状态图标的下方,并与它们重叠.

I am experiencing an issue when using Coordinator Layout that contains an AppBarLayout (holding a ToolBar and a TabLayout) and a ViewPager (holding fragments) as children. I want the topbar to be hidden when scrolling down, and revealed when scrolling back up. However when I scroll down, the status bar scrolls up as well, leaving the top bar just below the status icons, being overlapped by them.

我尝试将android:fitsSystemWindows ="true"添加到AppBarLayout和ViewPager中,但没有任何改变.

I tried adding android:fitsSystemWindows="true" to both the AppBarLayout and the ViewPager but nothing changed.

下面使用的代码和快照显示两种状态:

Below the code used and snapshots showing the two states:

<android.support.design.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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed"/>

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

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

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

推荐答案

查看活动的主题,如果主题类似于@ style/AppTheme.NoActionBar或一个没有ActionBar的主题,请尝试设置颜色,您必须具有颜色样式(v21)如下:

Review the theme for the activity, if the theme is like @style/AppTheme.NoActionBar or one theme without ActionBar, try putting a color, you must have a style(v21) something like this:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>    
</style>

更改为:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>

这篇关于Android状态栏以协调器布局向上滚动,而状态图标与工具栏标题重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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