Duplicate FragmentContainerView in Android navigation components

Viewed 316

I am creating a single activity application using jetpack navigation. Everything is working as expected. I have a requirement to make some fragments full screen.

Here is my layout xml.

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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_drawer"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/colorSurface"
    tools:context=".features.HomeActivity">

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

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/main_header"
        app:itemShapeInsetStart="0dp" />


</androidx.drawerlayout.widget.DrawerLayout>

As you can see I have used the android:fitsSystemWindows attribute in FragmentContainerView. But this is not working as expected and after inspecting the layout using Layout Inspector I am seeing duplicate FragmentContainerView in the view hierarchy.

Here is a screen shot of the view hierarchy. enter image description here

The problem this creates is that the first FragmentContainerView has the fitsSystemWindows attribute set to true but the second FragmentContainerView doesn't have that attribute set. I also tried the Advanced Navigation Sample and inspected the view and it also has the duplicate FragmentContainerView.

Can anyone please explain this to me? Thanks in advance.

0 Answers
Related