i want to hide bottom navigation bar so i am using bottom navigation behavior it works when i had other code but in this it seems not working i tried but bottom navigation bar
There are two things:
1) You should not override onNestedScroll
, it should be onNestedPreScroll
, delete onNestedScroll
and replace it with that:
@Override
public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
child.setTranslationY(Math.max(0f,
Math.min(Float.parseFloat(String.valueOf(child.getHeight())),child.getTranslationY()+dy)));
}
2) In your XML file, you put
app:layout_behavior=".Helper.BottomNavigationBehavior"
And your class name is
BottomNavigationBehaviour
As you can see one is Behaviour, and the other is Behavior, normally it should throw a runtime error, and the app shouldn't be able to run, it may be a typo on your part, but I mentioned it just in case.
But be aware that this code has a bug, if you try to scroll all the way down or up, the RecyclerView
item will not be clickable for a couple of seconds, I have a similar bug. For now, my choice is to use animation to hide the BottomNavigationView
as explained in this post.
EDIT:
It's possible that the behaviour is not applied because BottomNavigationView
is not a direct child of CoordinatorLayout
, so you can either delete the RelativeLayout
entirely or take the BottomNavigationView
out: