setfitsystemwindows无法工作windowtranslucentstatus coordinatorlayout

6

我正在做一个小型的Android项目。在显示状态栏下面的工具栏时遇到了一些问题。我使用以下配置:

  • 支持库版本23.2.0
  • windowTranslucentStatus = true
<CollapsingToolbarLayout fitSystemWindows="true" ...>
<FrameLayout fitSystemWindows="true" ...>
<ViewPager>
....consists a fragment with framelayout and image
</ViewPager>

<Toolbar fitSystemWindows="true" ...>

</FrameLayout>

<CollapsingToolbarLayout fitSystemWindows="true"...>
.....
</AppBarLayout>
</CoordinatorLayout>`

Image is displayed correctly but not the toolbar

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

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

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_collapseMode="parallax"
        android:fitsSystemWindows="true">
        <android.support.v4.view.ViewPager
            android:id="@+id/fragment_musicplayer_viewpager_test"
            android:layout_width="match_parent"
            android:layout_height="450dp" />

        <android.support.v7.widget.Toolbar
        android:id="@+id/fragment_musicplayer_toolbar_test"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true" />
    </FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
1个回答

2
如果你将 android:fitsSystemWindows="true" 中的一些改为 android:fitsSystemWindows="false",可能会起作用。
我遇到了与您类似的问题,使用的是支持库版本23.2.0,然后在StackOverflow上搜索,找到了您的问题。
我的情况与您相反,因为我的不需要顶部间距,但实际上有。尽管我设置了android:fitsSystemWindows="false",但什么也没变。
但我发现您设置了windowTranslucentStatus = true,我也这样做了。这是一个关键线索。
我敢把android:fitsSystemWindows="false"改为android:fitsSystemWindows="true"。它奏效了。
可能android:fitsSystemWindows的行为已经改变了。可能当windowTranslucentStatus = true时被倒置了。
--但仍然存在一个问题。当工具栏折叠时,工具栏的底边仍然对齐错误。我被迫放弃使用windowTranslucentStatus = true... 编辑23.2.1发布并修复了底边问题。但上述建议,即android:fitsSystemWindows的行为已被倒置仍然成立。

嗨,我打算试一下。通常我认为,我做的一切都是正确的,windowTranslucentStatus=true用于在状态栏后面显示Viewpager-Fragment,fitSystemWindows=true用于在状态栏下方显示工具栏。 - Hans
@hata,经过多次尝试在KK上使用Cordinator布局使状态栏半透明,看来我们应该让状态栏像ICS和JB一样变暗,并且只在21+版本中将其设置为透明或半透明:( - mfaisalhyder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接