如何在导航回来时再次显示BottomNavigationBar

问题描述 投票:0回答:1

当用户向下滚动时,我正在使用BottomNavigationBarHideBottomViewOnScrollBehavior来隐藏它,并在用户向上滚动时显示它。这非常有效。

但是,当隐藏因为用户向下滚动并向后导航回按钮时,我怎么能再次显示BottomNavigationBar

目前我的BottomNavigationView保持隐藏。

我正在使用支持库28.0.0

android show-hide bottomnavigationview
1个回答
0
投票

也许有人有更好的解决方案,但现在我想出了以下内容。

在我的SingleActivity应用程序的MainActivity中,我添加了以下函数来模拟滚动:

fun ensureBottomNavigation() {
    if(bottomNavigationView.translationY != 0f) {
        val layoutParams = bottomNavigationView.layoutParams as CoordinatorLayout.LayoutParams
        val behavior = layoutParams.behavior as HideBottomViewOnScrollBehavior

        behavior.onNestedScroll(container, bottomNavigationView, host_fragment.view!!, 0, -1, 0, 0, 0)
    }
}

在我的应用程序的每个片段中,我在onResume()中调用此函数,如下所示:

override fun onResume() {
    super.onResume()

    // Ensure that bottom navigation view is visible onResume()
    (activity as MainActivity).ensureBottomNavigation()
}
© www.soinside.com 2019 - 2024. All rights reserved.