Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable HideBottomViewOnScrollBehaviour

I currently have a bottom navigation bar inside a Coordinator layout, which I added a HideBottomViewOnScrollBehaviour to. Some screens require the navigation bar to be hidden, which I can achieve by calling the slideUp / slideDown methods from the behaviour object of BottomNavigationBar layout params.

The issue is, even if i'm hiding it programatically, you can reveal it by simply scrolling up again.

I didn't find any solutions, i was thinking there will be something like disabling the behaviour and enabling it on certain screens, but that's not a thing.

Any solutions?

Thanks!

like image 285
Gabi Avatar asked Apr 10 '26 03:04

Gabi


1 Answers

Here are methods to disable/enable scrolling behaviour:

fun enableLayoutBehaviour() {
    val params = navView?.layoutParams as CoordinatorLayout.LayoutParams
    if (params.behavior == null) {
        params.behavior = HideBottomViewOnScrollBehavior<View>()
    }
    navView?.let {
        (params.behavior as HideBottomViewOnScrollBehavior).slideUp(it)
    }
}

fun disableLayoutBehaviour() {
    val params = navView?.layoutParams as CoordinatorLayout.LayoutParams
    navView?.let {
        (params.behavior as HideBottomViewOnScrollBehavior).slideDown(it)
    }
    params.behavior = null
}

You can also just replace NestedScrollView with regular ScrollView on dedicated tabs to disable bottom bar from scrolling.

like image 115
VasiliyT Avatar answered Apr 12 '26 16:04

VasiliyT