底部导航视图显示不正确

Bottom Navigation View Is Shown Incorrectly

我的应用程序中有一些全屏活动,底部有底部导航视图。当应用程序有导航栏时,它看起来不错,像这样:

当我删除导航栏时,底部导航视图似乎填满了它的位置(而不是粘在布局底部):

这是我设置 android:layout_height="55dp" 而不是 "wrap_content" 时的样子:

我就是这样删除 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);
}

这是我的 activity 的 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>

可能是什么问题?

我 运行 并检查了你的代码。只需在隐藏导航栏时删除 "View.SYSTEM_UI_FLAG_LAYOUT_STABLE" 标志。它会解决你的问题!我希望您能理解为什么删除这个特定标志可以解决您的问题:)