android - 协调器布局和透明状态栏

标签 android android-layout android-design-library

我目前正在尝试使用协调器布局来折叠图像 - 在具有透明状态栏的主题中 - 但是三个问题困扰着我:

  1. 当 Activity 启动时,图像不会显示在状态栏后面(如果我删除 coordinatorlayout,它会工作);
  2. 当我向上滚动时,我想将状态栏更改为纯色,但仍然显示了一部分图像;
  3. 添加 AppBarLayout 和 CollapsingToolbarLayout 后,图像的底部 - 与状态栏的高度相同 - 被剪切;

image below status bar - even though it is set to be transparent in the theme 图像保持在状态栏下方 - 即使它在主题中设置为透明

Status bar after collapsing - it should have a solid color 折叠后的状态栏 - 它应该有纯色

代码:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:statusBarScrim="@color/colorPrimary"
            app:contentScrim="@color/colorPrimaryDark">

            <RelativeLayout
                android:id="@+id/cover_wrapper"
                android:layout_width="match_parent"
              android:layout_height="@dimen/rsc_character_details_cover_height">

                <ImageView
                    android:id="@+id/cover"
                    android:layout_width="match_parent"                 android:layout_height="@dimen/rsc_character_details_cover_height"/>
            </RelativeLayout>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="6">

           ...
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

这就是我设置状态栏透明度的方式:

<item name="android:windowTranslucentStatus">true</item>

任何帮助将不胜感激。 非常感谢。

最佳答案

对于状态栏后方图片不显示和被截断的问题,凡是应该显示在状态栏区域的都应该有android:fitsSystemWindows="true"。 IE。你的 cover_wrappercover

关于android - 协调器布局和透明状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36961655/

相关文章:

java - Android:Searchview 即使单击具有不同 id 的其他菜单项也会打开

android - 在 Android 中将 resourceId 分配给 Layout

android - float 按钮在 Lollipop 前版本中不起作用

android - 编辑文本中的密码可见性切换无法正常工作

android - 在 OnLayoutChangeListener 中更改 View 的大小

android.R.id.home 找不到符号

android - 移动/调整 EditText 大小时,windowSoftInputMode adjustPan 不起作用

android - 如果提供横向模式的替代布局,则纵向模式的共享动画不会动画。 (适用于 android 支持库 23.0.0)

android - 使用 Kotlin Android Extensions 以编程方式扩展布局

android - 如何在Android中以编程方式获取设备的完整屏幕尺寸?