https://kotlinlang.org logo
#android
Title
# android
o

onirutlA

06/01/2021, 12:55 AM
Hello guys need help to how to hide my appbar and bottom nav view when i'm scrolling, the appbar and toolbar is in the fragment and the bottom nav view is in activity and I'm using navigation component so how can i achieve that
Here is the Main Activity
Copy code
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".view.home.MainActivity">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/main_nav" />

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        app:layout_behavior="com.google.android.material.bottomappbar.BottomAppBar$Behavior"
        app:hideOnScroll="true">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_nav"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:labelVisibilityMode="selected"
            app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
            app:menu="@menu/bottom_nav_menu" />

    </com.google.android.material.bottomappbar.BottomAppBar>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
And here is the Fragment
Copy code
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".view.search.SearchFragment">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/search_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:contentInsetStartWithNavigation="0dp"
            app:navigationIcon="@drawable/ic_back_24"
            app:navigationIconTint="@color/white">

        </com.google.android.material.appbar.MaterialToolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/search_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:listitem="@layout/user_item" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
n

Nimish Nandwana

06/01/2021, 2:14 AM
user coordinator layout with scrolling behaviour
@onirutlA
o

onirutlA

06/01/2021, 2:47 AM
where do i need to put scrolling behavior
n

Nimish Nandwana

06/01/2021, 2:48 AM
@onirutlA in FragmentContainerView
o

onirutlA

06/01/2021, 3:35 AM
It didn't work toolbar hide on scroll but the bottomNav didn't hide, at first before i try your solution bottomNav hide on scroll
149 Views