状态栏(通知栏)上滚动消失与CoordinatorLayout [英] Status Bar (notification bar) is disappearing on scroll with CoordinatorLayout

查看:322
本文介绍了状态栏(通知栏)上滚动消失与CoordinatorLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的CoordinatorLayout使用Android Studio中的默认模板。

I am using the CoordinatorLayout using the default templates in Android Studio.

然而,当我向下滚动,通知栏(状态栏)的滚动关闭屏幕。效果可以在该视频中可以看出。
https://youtu.be/1oAqEpg7N4I

However when I scroll down, the notification bar (status bar) is scrolling off screen. The effect can be seen in this video. https://youtu.be/1oAqEpg7N4I

我已经包含了相关的零件,而是code的其余部分可在这里:
<一href=\"https://github.com/vidia/MaterialDiningCourts/blob/master/app/src/main/res/layout/activity_meal_view.xml\" rel=\"nofollow\">https://github.com/vidia/MaterialDiningCourts/blob/master/app/src/main/res/layout/activity_meal_view.xml

I have included the relevant parts, but the rest of the code is available here: https://github.com/vidia/MaterialDiningCourts/blob/master/app/src/main/res/layout/activity_meal_view.xml

在演示( cheesesquare )的行为是我所期望的,要留在原地通知栏和工具栏滚动出它的下面。我已经冲刷的布局,并改变了我的code更改,以适合他们,但一直没能找到必要的改变。

In the demo (cheesesquare) the behavior is what I expect, to leave the notification bar in place and the Toolbar scrolls out underneath it. I have scoured those layouts and made changes in my code to match them, but haven't been able to find the necessary change.

是什么原因造成的通知栏滚动出页面,为什么Android Studio中的样品有这种不正确的行为?

What is causing the notification bar to scroll off the page, and why does the sample in Android Studio have this incorrect behavior?

<?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=".MealViewActivity">

<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.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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|snap"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <Spinner
            android:id="@+id/meal_chooser_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </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:theme="@style/AppTabLayout"
        android:foregroundGravity="top"
        app:tabIndicatorColor="@color/tabSelectedIndicatorColor"/>
</android.support.design.widget.AppBarLayout>

和styles.xml,虽然我已经从该文件中删除我的自定义主题,它不利于问题。

And styles.xml, though I have removed my custom themes from this file and it doesnt help the issue.

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!-- Required from http://stackoverflow.com/a/29014475/2193387 -->
    <item name="android:datePickerDialogTheme">@style/dateDialogTheme</item>

</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppTabLayout" parent="Widget.Design.TabLayout">
    <!--<item name="tabMaxWidth">@dimen/tab_max_width</item>-->
    <item name="tabIndicatorColor">@color/tabIndicatorColor</item>
    <item name="tabIndicatorHeight">4dp</item>
    <!--<item name="tabPaddingStart">6dp</item>-->
    <!--<item name="tabPaddingEnd">6dp</item>-->
    <!--<item name="tabBackground">?attr/selectableItemBackground</item>-->
    <item name="tabTextAppearance">@style/AppTabTextAppearance</item>
    <item name="tabSelectedTextColor">@color/white</item>
</style>

<style name="AppTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:textSize">12sp</item>
    <item name="android:textColor">@color/tabUnselectedTextColor</item>
    <item name="textAllCaps">true</item>
</style>

<!-- TODO: Change to use AppCompat rather than Material -->
<style name="dateDialogTheme" parent="android:Theme.Material.Light.Dialog">
    <!-- Required from http://stackoverflow.com/a/29014475/2193387 -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

推荐答案

在消失状态栏的效果是这些定义中的结果值-21 / styles.xml:

The disappearing status bar effect is the result of these definitions in values-21/styles.xml:

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

使用这些定义,系统不再绘制系统栏背景。你看到的状态栏背景是什么CoordinatingLayout实际计提,超越现在,透明的系统吧。现在,当你滚动,滚动CoordinatedLayout起来AppBarLayout,其内容是通过透明的系统栏中。

With these definitions, the system no longer draws system bar background. What you see as status bar background is actually drawn by CoordinatingLayout, beyond the now-transparent system bar. Now, when you scroll, CoordinatedLayout scrolls AppBarLayout up, and its content is visible through the transparent system bar.

您有两个选项来解决这个问题:

You have two options to fix this:


  • 请在状态栏不透明

  • 此外使用CollapsingToolbarLayout,并设置状态栏粗布

这篇关于状态栏(通知栏)上滚动消失与CoordinatorLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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