Im trying to add hide/show behaviour for bottom nav view but its not working
im refering to this answer
according to that answer i have added the app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
but it didnt worked, probably becuase that the reyclerview that im having is in a fragment and the bottom nav is in the main activity, but im not sure
Here is activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e7e7e7"
tools:context=".MainActivity">
<TextView
android:id="@+id/goodbyetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/calibriregular"
android:text="Goodbye"
android:textAlignment="center"
android:textColor="#36332c"
android:textSize="50sp" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/appToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#e7e7e7"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/calibriregular"
android:text="That Button Again"
android:textAlignment="center"
android:textColor="#36332c"
android:textSize="25dp" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/aboutPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|end"
android:layout_margin="10dp"
android:background="@drawable/border"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#fffdf6"
android:orientation="vertical">
<com.indiedev91.thatbuttonagain.DotsTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include
android:id="@+id/fragment_container"
layout="@layout/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="10dp"
android:background="@drawable/border">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_navigation_style"
app:itemIconSize="30dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="@color/buttonText"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
app:menu="@menu/bottom_nav_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
and here is the fragment buttons
which contains the reyclerview
fragment_buttons.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e7e7e7"
tools:context=".ButtonsFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/btnRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:fitsSystemWindows="true"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</androidx.recyclerview.widget.RecyclerView>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/fragment_container"
layout="@layout/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
and just for a note that the coordinator layout i used just above the bottom nav in main activity xml is to apply a border
also as this was not working i tried the programmatically , so in the fragment button java
ButtonsFragment.java
bottomNavigationView = getActivity().findViewById(R.id.bottomNavigationView);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0 && bottomNavigationView.isShown()) {
bottomNavigationView.setVisibility(View.GONE);
} else if (dy < 0) {
bottomNavigationView.setVisibility(View.VISIBLE);
}
}
});
but as you can guess this dosent give the slide down and slide up animation style that i can get from the behaviour of HideBottomViewOnScrollBehavior