Collapsing toolbar with navigation ui android

Viewed 126

I' am trying everything but I don't know how to do a collapsing toolbar with a jetpack navigation fragment. I want this in my screen :

  • Toolbar (with collapse mode)
  • Fragment loading by Navigation Jetpack
  • AdView (from admob)
  • BottomNavigationView

I tried change order of relative layout and coordinator, but nothing works, in my app. I have a recycler view on fragments, and when I'm using the scroll, toolbar doesn't hide.

My code is:

<RelativeLayout 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=".activies.MainActivity">


    <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/adView"
            android:fitsSystemWindows="true">

        <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/appBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:theme="@style/AppTheme">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar_layout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    app:titleEnabled="false"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleGravity="top"
                    app:expandedTitleMarginStart="48dp"
                    app:expandedTitleMarginEnd="64dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight"
                    app:titleTextColor="@android:color/white"
                    app:layout_scrollFlags="scroll|enterAlways" />
            </com.google.android.material.appbar.CollapsingToolbarLayout>

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

        <fragment
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                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/nav_graph" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <FrameLayout
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignWithParentIfMissing="true"
            android:layout_above="@+id/bottomNavigation"
            android:layout_gravity="center"
            android:gravity="center"
            android:visibility="gone" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:theme="@style/BottomNavigationTheme"
            app:menu="@menu/menu_navigation_bottom">

    </com.google.android.material.bottomnavigation.BottomNavigationView>


</RelativeLayout>

Someone can help me? Thank you so much.

0 Answers
Related