简体   繁体   中英

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

I have BottomNavigationView with three fragments. First one has a RecyclerView and I implemented to hide Toolbar after scrolling this RecyclerView and it works. When I change fragment I would like to show it again (actionbar) - but actionbar.isShowing() returns true and actionbar.show() doesn't work. Maybe somebody has an idea?

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>

When you change fragments you should call AppBarLayout.setExpanded(true)

Can you show us some code on how are you making the toolbar disappear?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM