【问题标题】:How to show BottomNavigationBar again on navigate back如何在向后导航时再次显示 BottomNavigationBar
【发布时间】:2019-02-25 11:49:28
【问题描述】:

我使用BottomNavigationBarHideBottomViewOnScrollBehavior 在用户向下滚动时隐藏它并在用户向上滚动时显示它。这很好用。

但是,当 BottomNavigationBar 因为用户向下滚动并通过后退按钮导航返回时它被隐藏时,我如何才能再次显示它?

目前我的BottomNavigationView 保持隐藏状态。

我正在使用支持库28.0.0

【问题讨论】:

    标签: android show-hide bottomnavigationview


    【解决方案1】:

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

    在我的 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()
    }
    

    【讨论】:

    • 更好的决策行为.slideUp(bottomNavigationView)
    • @EugeneP。完美的解决方案。
    猜你喜欢
    • 2014-12-27
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多