android - 底部导航 View 显示不正确

标签 android android-layout view bottomnavigationview

我的应用程序中有一些全屏 Activity ,底部有底部导航 View 。当应用程序有导航栏时,它看起来很好,如下所示:

enter image description here

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

enter image description here

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

enter image description here

这就是我删除导航栏的方法:

@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”标志即可。它会解决你的问题!我希望您能理解为什么删除这个特定标志可以解决您的问题:)

关于android - 底部导航 View 显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60134630/

相关文章:

android - 设备语言为英文时如何加载arabic string.xml

android - SQLITE - 删除第 n 行 (Android)

android - 如何在 TextView 中添加项目符号?

android - 在运行时使用 MVVM 中的数据添加绑定(bind) View

javascript - AngularJS View 未填充

android - 如何在android中的 fragment 列表适配器中设置可绘制图像

java - 安卓java : foreach through json array returning values?

android - "?attr/colorPrimary"的值

android - 如何从android中的后台服务获取 View ?

Postgresql 数据库物化 View 在复制时刷新