简体   繁体   English

Android 隐藏后如何显示工具栏(通过在 RecyclerView 中向下滚动)

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

I have BottomNavigationView with three fragments.我有带有三个片段的BottomNavigationView First one has a RecyclerView and I implemented to hide Toolbar after scrolling this RecyclerView and it works.第一个有一个RecyclerView ,我实现了在滚动这个 RecyclerView 后隐藏工具栏,它可以工作。 When I change fragment I would like to show it again (actionbar) - but actionbar.isShowing() returns true and actionbar.show() doesn't work.当我更改片段时,我想再次显示它(actionbar) - 但 actionbar.isShowing() 返回 true 并且 actionbar.show() 不起作用。 Maybe somebody has an idea?也许有人有想法?

activity_main.xml 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)当您更改片段时,您应该调用AppBarLayout.setExpanded(true)

Can you show us some code on how are you making the toolbar disappear?您能否向我们展示一些有关如何使工具栏消失的代码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 向下滚动后隐藏CoordinatorLayout中的工具栏 - Hiding toolbar in CoordinatorLayout after scrolling down 如何在recyclelerView向下滚动时折叠后隐藏工具栏 - How to hide toolbar after collapsing while recyclerView scrolling down 在嵌套片段中滚动RecyclerView时隐藏工具栏 - Hiding Toolbar when Scrolling a RecyclerView in nested Fragment 当您停止在android中滚动listview / recyclerview时,如何隐藏或显示部分隐藏的工具栏/操作栏 - How to hide or show the partially hidden toolbar/actionbar when you stop scrolling the listview/recyclerview in android 在Android中向下滚动RecyclerView - scrolling down RecyclerView in Android 向下滚动所有项目后,在RecyclerView下面显示视图 - Show View below RecyclerView after scrolling all items down Android:向上滚动时显示工具栏(向上拖动),向下滚动时隐藏(向下拖动) - Android: Show toolbar when scrolling UP(Drag UP) and hide when scrolling down(Drag down) 向上和向下滚动列表后,Android 图像在 RecyclerView 中消失? - Android Image disappear in RecyclerView after Scrolling list up and down? 滚动时,Android“更平滑”隐藏工具栏 - Android “smoother” hiding of Toolbar when scrolling 工具栏不会自动隐藏,在recyclerview中滚动时需要手动按下才能隐藏 - toolbar is not hiding automatically need to push manually to hide while scrolling in recyclerview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM