簡體   English   中英

滾動時在CoordinatorLayout中隱藏工具欄和BottomBar-在透明狀態欄下可見

[英]Hide Toolbar and BottomBar in CoordinatorLayout when scrolling - visible under transparent status bar

我有NavigationDrawer ToolbarBottomBar主要活動。 活動內部是片段的容器。 並且該片段具有RecyclerView 因此,當用戶滾動時,我想相應地隱藏ToolbarBottomBar 我通過在回收站app:layout_behavior="@string/appbar_scrolling_view_behavior"上使用布局行為來做到這一點app:layout_behavior="@string/appbar_scrolling_view_behavior"並在工具欄上使用布局滾動標志app:layout_scrollFlags="scroll|enterAlways|snap" 對於BottomBar,我正在使用此庫: https : //github.com/roughike/BottomBar

問題是,當ToolbarBottomBar Toolbar滾動到視圖之外時,它們仍在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標志時-工具欄位於stauts欄下方

當未設置fitsSystemWindows標志時

當未設置fitsSystemWindows標志並滾動內容時-工具欄正確隱藏,但導航欄在導航欄下方仍可見

當未設置fitsSystemWindows標志且滾動內容時

當fitsSystemWindows標志設置為root協調器時-正常狀態看起來正常

當fitsSystemWindows標志設置為root協調器時

當fitsSystemWindows標志設置為root協調器並滾動內容時-在透明狀態欄和導航欄下方可見狀態欄和底部裸露

當fitsSystemWindows標志設置為root協調器並且內容滾動時

有人可以幫我做錯什么嗎? 我已經在不同的視圖上嘗試過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;
  }

要在滾動條上隱藏BottomBar,您需要設置app:bb_behavior =“ shy”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM