Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setfitsystemwindows not working windowtranslucentstatus coordinatorlayout

I am working on a small Android project. I am having some problems while displaying the toolbar below the status bar. I am using the following config:

  • Support library version 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>
like image 403
Hans Avatar asked Nov 09 '22 19:11

Hans


1 Answers

If you change some of android:fitsSystemWindows="true" to android:fitsSystemWindows="false", it may work.

I faced similar problem with yours with Support library version 23.2.0, and then searched StackOverflow; found your question.

My case was opposite to yours because mine didn't need top-margin spacing but it had. Although I set android:fitsSystemWindows="false", but nothing changed.

But I found that you set windowTranslucentStatus = true and so did I. It was a key clue.

I dared to change android:fitsSystemWindows="false" to android:fitsSystemWindows="true". It worked.

It may be that the behavior of android:fitsSystemWindows has been changed. Possibly it has been inverted when windowTranslucentStatus = true.

--But there remains a problem. When the toolbar is collapsed, the bottom bound of the toolbar is still aligned wrongly. I've forced to abandon to use windowTranslucentStatus = true...

EDIT: 23.2.1 was released and the bottom bound problem was fixed. But the above suggestion that the behavior of android:fitsSystemWindows has been inverted is still true.

like image 86
hata Avatar answered Nov 25 '22 22:11

hata