【问题标题】:Exploring fitsSystemWindows and transparent status bar in android探索fitsSystemWindows和android中的透明状态栏
【发布时间】:2015-07-25 06:02:48
【问题描述】:

请假设所有内容仅适用于目标,minSDK 版本仅适用于棒棒糖。

我想要什么

我正在尝试从 Play 商店实现类似于以下屏幕的活动。

我在这里专注于英雄形象。如你所见, 1.英雄形象绘制在状态栏后面。 (完全透明。无保护) 2. 其余内容绘制在状态栏下方。 (例如,工具栏/操作栏) 3.滚动时状态栏是彩色的。

我做了什么

我使用了来自 GoogleIO 应用的 ScrimInsetsFrameLayout。围绕这个布局包裹了我的英雄形象。在我的主题中添加了适当的样式。这就是我得到的

我需要帮助

  1. 我仍然对 fitSystemWindows 标签感到困惑。当我在英雄图像布局上将此设置为“true”时,什么也没有发生。即状态栏是透明的,但图像是在状态栏下方绘制的。如果设置为“false”,我会得到上述结果。有没有明确的文章说明这个标签的用法和幕后花絮。

  2. 我将 ScrimInsetFrameLayout 上的“insetForeground”设置为透明。同样在主题中,我将状态栏颜色设置为透明。但是仍然有对图像的保护。如何让状态栏完全透明。

请帮助我提供指针或演示项目。如果我不清楚或需要更多信息,也请告诉我。

【问题讨论】:

    标签: android


    【解决方案1】:

    这对我有用。

    layout.xml

    <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: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:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginEnd="64dp"
                    app:expandedTitleMarginStart="48dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
                    <ImageView
                        android:id="@+id/backdrop"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:fitsSystemWindows="true"
                        android:scaleType="centerCrop"
                        app:layout_collapseMode="parallax" />
    
                    <android.support.v7.widget.Toolbar
                        android:id="@+id/parallax_toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
                </android.support.design.widget.CollapsingToolbarLayout>
    
            </android.support.design.widget.AppBarLayout>
    
            <FrameLayout
                android:id="@+id/fragmentContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
        </android.support.design.widget.CoordinatorLayout>
    

    并在styles.xml v-21设置statusBarColor属性为透明色

    【讨论】:

    • 这怎么能在状态栏后面有一个图像,上面没有透明的纱布?
    • 在 ImageVied 中设置 android:fitsSystemWindows="true" 为我解决了这个问题,谢谢
    • 添加,使用前需要在 values21/styles.xml 中设置 fistystemwidows true
    【解决方案2】:

    将以下行添加到您不希望工具栏重叠的视图中:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 2015-03-29
      • 1970-01-01
      相关资源
      最近更新 更多