Tal Barda
Tal Barda

Reputation: 4277

Bottom Navigation View Is Shown Incorrectly

I have some full-screen activities in my app which have bottom navigation view at the bottom. When the app has the navigation bar on it looks fine, like this:

enter image description here

When I remove the navigation bar, it seems like the bottom navigation view fills its place (instead of sticking to the bottom of the layout):

enter image description here

This is how it looks when I set android:layout_height="55dp" instead of "wrap_content":

enter image description here

This is how I remove the navigation bar:

@Override
public void onResume(){
    super.onResume();
    View aView = getWindow().getDecorView();
    aView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

This is the code of my activity's XML:

<FrameLayout
    android:id="@+id/main_activity_fragment_container"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    app:layout_constraintBottom_toTopOf="@+id/navigation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</FrameLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:backgroundTint="@color/colorPrimary"
    app:itemIconTint="@color/bnv_colors_main_menu"
    app:itemTextColor="@color/bnv_colors_main_menu"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/navigation_main_menu"
    app:labelVisibilityMode="labeled"
    >

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

What could be the problem?

Upvotes: 2

Views: 485

Answers (1)

Md Golam Rahman Tushar
Md Golam Rahman Tushar

Reputation: 2375

I ran and checked your code. Just remove the "View.SYSTEM_UI_FLAG_LAYOUT_STABLE" flag while hiding the navigation bar. It will solve your problem! And I hope you would understand why removing this specific flag solves your problem :)

Upvotes: 2

Related Questions