2

我的主要活動有NavigationDrawerToolbarBottomBar。活動內部是碎片的容器。片段有RecyclerView。所以當用戶滾動時,我想相應地隱藏ToolbarBottomBar。我在工具欄上使用回收站app:layout_behavior="@string/appbar_scrolling_view_behavior"上的佈局行爲和佈局滾動標誌app:layout_scrollFlags="scroll|enterAlways|snap"。對於BottomBar我使用這個庫:https://github.com/roughike/BottomBar隱藏滾動條中CoordinatorLayout中的工具欄和BottomBar - 在透明狀態欄下可見

的問題是,當ToolbarBottomBar都滾出來看,他們仍在對StatusBarNavBar

我的代碼可見:

風格:

<style name="TranslucentStatusTheme" parent="AppTheme"> 
     <item name="android:windowTranslucentNavigation">false</item> 
     <item name="android:windowTranslucentStatus">true</item> 
     <item name="android:windowContentOverlay">@null</item> 
</style> 

主要活動內容:

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/app_bar_main_coordinator" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.test.activity.MainActivity" 
    > 

    <android.support.design.widget.AppBarLayout 
     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="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      /> 

    </android.support.design.widget.AppBarLayout> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottomBar" 
     android:fitsSystemWindows="true" 
     /> 

    <com.roughike.bottombar.BottomBar 
     android:id="@+id/bottomBar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/bottom_bar_menu_height" 
     app:bb_activeTabColor="@color/colorAccent" 
     app:bb_behavior="shifting|shy|underNavbar" 
     app:bb_inActiveTabColor="@color/bottom_bar_inactive_tab_color" 
     app:bb_tabXmlResource="@xml/bottombar_tabs" 
     app:layout_anchor="@id/container" 
     app:layout_anchorGravity="bottom" 
     android:layout_gravity="bottom" 
     /> 

</android.support.design.widget.CoordinatorLayout> 

和我的問題的照片:

當沒有fitsSystemWindows標誌設置 - 工具欄下方狀態,請執行吧

When no fitsSystemWindows flag is set

當沒有fitsSystemWindows標誌設置和內容滾動 - 工具欄是隱藏正確,但bootom欄仍低於導航欄可見

When no fitsSystemWindows flag is set and content is scrolled

當fitsSystemWindows標誌設置爲根協調 - 正常狀態看起來不錯

When fitsSystemWindows flag is set to root coordinator

當fitsSystemWindows標誌設置爲根協調和滾動內容 - 狀態欄和底部是裸露的透明狀態欄和導航欄下方可見

When fitsSystemWindows flag is set to root coordinator and content is scrolled

任何人可以幫助我什麼我」米做錯了嗎?我已經在不同視圖上嘗試過所有可能的fitsSystemWindows組合。

編輯:

我固定工具欄下方狀態欄的問題,但我不認爲解決的辦法是乾淨的。我仍然在尋找更好的。我仍然解決不了底欄問題

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
    toolbar.setPadding(0, getStatusBarHeight(), 0, 0); 
} 
..... 
// A method to find height of the status bar 
private int getStatusBarHeight() { 
     int result = 0; 
     int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); 
     if (resourceId > 0) { 
     result = getResources().getDimensionPixelSize(resourceId); 
     } 
     return result; 
    } 

回答

0

要隱藏BottomBar上滾動,你需要設置的應用程序:bb_behavior =「害羞」

<com.roughike.bottombar.BottomBar 
    android:id="@+id/bottomBar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/bottom_bar_menu_height" 
    app:bb_activeTabColor="@color/colorAccent" 
    app:bb_behavior="shy" 
    app:bb_inActiveTabColor="@color/bottom_bar_inactive_tab_color" 
    app:bb_tabXmlResource="@xml/bottombar_tabs" 
    app:layout_anchor="@id/container" 
    app:layout_anchorGravity="bottom" 
    android:layout_gravity="bottom" 
    /> 
我已經使用這個行爲滾動
+0

,但如果我使用它,因爲它是我的示例應用程序:bb_behavior =「shifting | shy | underNavbar」,則存在我在問題和圖像中描述的問題。 – Sandak

+0

我剛剛使用app:bb_behavior =「shy」,而不是「轉換|害羞| underNavbar」,對我來說底欄,在導航欄中不可見。請檢查在https://github.com/roughike/BottomBar中運行應用程序和代碼。「快速返回三個選項卡」。 – Annada

+0

由於您的「導航欄」不透明,導航欄下方不可見。正如你在我的圖片中看到的,我有透明的「導航欄」,因此我必須設置「underNavbar」行爲。在來自版本庫的樣本中,沒有'shy'和'underNavbar'組合的樣本。但是如果我查看Material Design指南,建議在屏幕上有更多內容的透明「導航欄」:https://material.google.com/components/bottom-navigation.html#bottom-navigation-behavior – Sandak