I have a CoordinatorLayout
that contains a BottomNavigationView
and an AppBarLayout
with a ToolBar
inside of it. (The BottomNavigationView
is not inside the AppBarLayout
, as doing it breaks the position of the BottomNavigationView
).
I need to show/hide the AppBarLayout
and the BottomNavigationView
programmatically, when certain events happen (e.g. on a fragment's onResume
), and so far I've managed setting appBarLayout.setExpanded(true, true)
in order to show/hide the AppBar, but I can't figure out how to do the same for the BottomNavigationView
, as it does not have any method to show/hide itself.
The behaviour of my BottomNavigationView
is app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
, set in the layout xml. How can I get a reference to this behaviour in my code in order to manage its expanded/collapsed state?
Thats code slides up your bottom navigation that are inside of a Coordinator Layout and have a HideBottomViewOnScrollBehavior.
If you are using findViewById just replace that for every binding.
val layoutParams = binding.bottomNavigation.layoutParams as CoordinatorLayout.LayoutParams
val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior
bottomViewNavigationBehavior.slideUp(binding.bottomNavigation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With