簡體   English   中英

Android 隱藏后如何顯示工具欄(通過在 RecyclerView 中向下滾動)

[英]Android how to show toolbar after hiding (by scrolling down in RecyclerView)

我有帶有三個片段的BottomNavigationView 第一個有一個RecyclerView ,我實現了在滾動這個 RecyclerView 后隱藏工具欄,它可以工作。 當我更改片段時,我想再次顯示它(actionbar) - 但 actionbar.isShowing() 返回 true 並且 actionbar.show() 不起作用。 也許有人有想法?

activity_main.xml

<androidx.coordinatorlayout.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:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@android:color/white"
     tools:context=".main.MainActivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/mainToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:title="@string/app_name"/>

</com.google.android.material.appbar.AppBarLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/mainNav"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@android:color/white"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    app:menu="@menu/user_tabs_menu" />

<FrameLayout
    android:id="@+id/mainFrameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

當您更改片段時,您應該調用AppBarLayout.setExpanded(true)

您能否向我們展示一些有關如何使工具欄消失的代碼?

暫無
暫無

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

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