Monday, 22 March 2021

How to implement a backdrop with NavigationView?

I am looking for a backdrop like implementation. With a toolbar at the top a NavigationView below it and a BottomSheet. The BottomSheet holds the content and I need it to be draggable and will hide and show the NavigationView

This is what I want

This is what I want

This is my XML-->

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            app:layout_collapseMode="pin"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:titleTextColor="@color/black" />

        <com.google.android.material.navigation.NavigationView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:translationZ="-10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/toolbar"
            app:menu="@menu/navigation" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:translationZ="10dp"
        app:behavior_peekHeight="64dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar">

        <fragment
            android:id="@+id/nav_host_fragment_container"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:defaultNavHost="true"
            app:navGraph="@navigation/nav_graph" />
    </LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>


from How to implement a backdrop with NavigationView?

No comments:

Post a Comment