从ViewPager第2页CoordinatorLayout状态

从ViewPager第2页CoordinatorLayout状态

本文介绍了从ViewPager第2页CoordinatorLayout状态栏填充消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的23/7/2015编辑:支持设计库v22.2.1没修好:-(也发生这种情况对MainActivity工具栏回报快

编辑28/7/2015:链接的问题:CoordinatorLayout在片段的交易状态栏填充消失

这是例子库 https://github.com/chrisbanes/cheesesquare 我已经详细活动实施ViewPager。它的工作原理,但状态栏,从第2页消失,你在图片中看到的只有棒棒堂设备的,你知道吗?我用安卓fitsSystemWindows =真正的,但它的工作只在第一页: - (

activity_detail_viewpager.xml 如果我把这里fitsSystemWindows,状态栏不是透明的了,但它的工作原理(状态栏填充不会丢失)。但我想它透明!

 < android.support.design.widget.CoordinatorLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
        机器人:ID =@ + ID / main_content
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>

    < android.support.v4.view.ViewPager
        机器人:ID =@ + ID / viewpager
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:overScrollMode =ifContentScrolls/>

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

activity_detail_fragment.xml

 < CoordinatorLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID / main_content
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:fitsSystemWindows =真正的>

    < android.support.design.widget.AppBarLayout
        机器人:ID =@ + ID / appbar
        机器人:layout_width =match_parent
        机器人:layout_height =@扪/ detail_backdrop_height
        机器人:fitsSystemWindows =真
        机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar>

        < android.support.design.widget.CollapsingToolbarLayout
            机器人:ID =@ + ID / collapsing_toolbar
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:fitsSystemWindows =真
            应用程序:layout_scrollFlags =滚动| exitUntilCollapsed
            应用程序:contentScrim =?ATTR / colorPrimary
            应用程序:expandedTitleMarginStart =48dp
            应用程序:expandedTitleMarginEnd =64dp>

            < ImageView的
                机器人:ID =@ + ID / back_item
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:scaleType =centerCrop
                机器人:fitsSystemWindows =真
                应用程序:layout_collapseMode =视差/>

            < android.support.v7.widget.Toolbar
                机器人:ID =@ + ID /工具栏
                机器人:layout_width =match_parent
                机器人:layout_height =?ATTR / actionBarSize
                应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light
                应用程序:layout_collapseMode =针/>

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

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

    < android.support.v4.widget.NestedScrollView
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior>

        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:方向=垂直
            机器人:paddingTop =24dp>

            < android.support.v7.widget.CardView
                机器人:layout_width =match_parent
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_margin =@扪/ card_margin>

                ...

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

            ...

        < / LinearLayout中>

    < /android.support.v4.widget.NestedScrollView>

    < android.support.design.widget.FloatingActionButton
        机器人:ID =@ + ID /晶圆厂
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_margin =@扪/ fab_margin
        机器人:可点击=真
        机器人:SRC =@可绘制/ ic_discuss
        应用程序:layout_anchor =@ ID / appbar
        应用程序:layout_anchorGravity =底部|结束
        应用:边框宽度=0dp/>

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

style.xml V21

 <资源>
    <样式名称=AppTheme父=AppTheme.Base>
        <项目名称=机器人:windowDrawsSystemBarBackgrounds>真< /项目>
        <项目名称=机器人:statusBarColor> @android:彩色/透明< /项目>
    < /风格>
< /资源>
 

解决方案

好像这个解决方案很简单

 安卓fitsSystemWindows =真
 

在片段CoordinateLayoutView

从这里取出并放在在活动的根本看法。

这应该现在所有的工作

EDIT of 23/7/2015: Support Design Library v22.2.1 didn't fix :-( Also this happens on toolbar quick return on MainActivity!

EDIT of 28/7/2015: Linked question: CoordinatorLayout status bar padding disappears during fragment transactions

From example repository https://github.com/chrisbanes/cheesesquare I've implemented the ViewPager on Detail Activity. It works, but the StatusBar disappears from 2nd page as you see in the picture only in Lollipop devices, Any idea?I use android:fitsSystemWindows="true" but it does work only on first page :-(

activity_detail_viewpager.xmlif I put here fitsSystemWindows, StatusBar is not transparent anymore, but it works (status bar padding is not lost). But I would like it transparent!

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:overScrollMode="ifContentScrolls"/>

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

activity_detail_fragment.xml

<CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/detail_backdrop_height"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/back_item"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/card_margin">

                ...

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

            ...

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"
        android:src="@drawable/ic_discuss"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|end"
        app:borderWidth="0dp"/>

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

style.xml v21

<resources>
    <style name="AppTheme" parent="AppTheme.Base">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>
解决方案

Seems the solution for this is simple

You have

android:fitsSystemWindows="true"

In the fragment CoordinateLayoutView

remove it from here and put in the Activity's root view.

This should now all work

这篇关于从ViewPager第2页CoordinatorLayout状态栏填充消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:55