5

我正在開發一個小型Android項目。在狀態欄下方顯示工具欄時遇到一些問題。我使用以下配置:setfitsystemwindows not working windowtranslucentstatus coordinatorlayout

  • 支持庫版本23.2.0
  • windowTranslucentStatus =真

<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> 

回答

0

如果您將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的行爲已被顛倒過來。

+0

嗨,我要去嘗試一下。通常我認爲,我做的一切都是正確的,windowTranslucentStatus = true用於在statusbar後面顯示Viewpager-Fragment,fitSystemWindows = true在狀態欄 – Hans

+0

@hata之後顯示工具欄,經過這麼多嘗試使Cordinator佈局能夠使用半透明狀態欄在KK上,似乎我們應該讓狀態欄像ICS和JB一樣黑暗,並且只讓21+ :(透明或半透明) –