How to show BottomNavigationBar again on navigate back

狂风中的少年 提交于 2019-12-25 01:43:49

问题


I'm using a BottomNavigationBar with HideBottomViewOnScrollBehavior to hide it when user scrolls down and display it when user scrolls up. This works great.

But how can i show the BottomNavigationBar again when it's hidden because user scrolled down and navigates back over back button?

At the moment my BottomNavigationView stays hidden.

I'm using support library 28.0.0


回答1:


Maybe somebody has a better solution for this, but for now i came up with the following.

In my MainActivity of my SingleActivity app i added the following function to simulate up scrolling:

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)
    }
}

In every Fragment of my app i'm calling this function in onResume() like this:

override fun onResume() {
    super.onResume()

    // Ensure that bottom navigation view is visible onResume()
    (activity as MainActivity).ensureBottomNavigation()
}


来源:https://stackoverflow.com/questions/54865536/how-to-show-bottomnavigationbar-again-on-navigate-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!