2

I have discovered a very strange behavior today. This is my BottomNavigationView.

<androidx.constraintlayout.widget.ConstraintLayout 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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/darkPurple"
    android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="@color/fillColorDark"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:menu="@menu/bottom_nav_menu"
        app:itemIconTint="@color/bottom_navigation_color"
        app:itemTextColor="@color/bottom_navigation_color"
        app:labelVisibilityMode="labeled"/>

    <fragment
        android:id="@+id/nav_host_fragment_activity_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation"
        tools:ignore="FragmentTagUsage" />

</androidx.constraintlayout.widget.ConstraintLayout>

And this is the behavior :

  • Launching my app in landscape, all fine
  • Launching my app in portrait, all fine
  • Launching my app in portrait and then rotate for landscape, bottom bar hide main layout !

If anyone have an idea it gonna be grateful

EDIT : entire layout
EDIT 2 : Add videos

Landscape safe

landscape safe

Landscape broken

Landscape broken

Marine Droit
  • 101
  • 8

1 Answers1

0

I had this exact problem 2 years ago.

I have managed to create a custom one purely with XML and no code to avoid this problem.

Link to my old solution: https://stackoverflow.com/a/61349651/12969368

gcantoni
  • 727
  • 6
  • 13
  • I don't know if your solution can fit to my problem. I use several callback like addOnDestinationChangedListener it works with your custom bar ? – Marine Droit Oct 18 '22 at 07:02