You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中BottomNavigationView被系统导航栏遮挡问题求助

解决BottomNavigationView被系统导航栏遮挡的问题

问题分析

当前布局存在两个核心问题:

  • 根布局的android:fitsSystemWindows="true"未正确传递窗口边距,且RecyclerView使用固定宽高(409dp/671dp),导致布局适配逻辑混乱
  • BottomNavigationView直接绑定到父布局底部,未预留系统导航栏的空间

解决方案

按以下步骤修改布局:

  1. 修正根布局属性
    移除根布局中无效的app:layout_constraintBottom_toTopOf="@id/navbar"(ConstraintLayout自身无需该约束),确保android:fitsSystemWindows="true"生效,保留android:clipToPadding="false"让子布局可延伸至窗口边距外。

  2. 调整RecyclerView的宽高约束
    将RecyclerView的固定宽高改为match_parent,依赖约束控制位置,避免固定dp引发的适配问题,同时保留必要的padding设置。

  3. 让BottomNavigationView避开系统导航栏
    在BottomNavigationView上添加android:fitsSystemWindows="true",或直接设置底部边距为系统导航栏高度android:layout_marginBottom="?android:attr/navigationBarHeight",确保底部约束正确绑定到父布局底部。

修改后的完整布局代码

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layoutDirection="rtl"
        android:paddingTop="@dimen/_30sdp"
        android:paddingRight="@dimen/_5sdp"
        android:paddingBottom="@dimen/_30sdp"
        android:scrollbars="vertical"
        android:clipToPadding="false"
        app:layout_constraintBottom_toTopOf="@+id/navbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layoutDirection="rtl"
        android:fitsSystemWindows="true"
        android:foreground="?attr/selectableItemBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/navbar"
        style="@style/BottomNavigationView" />

</androidx.constraintlayout.widget.ConstraintLayout>

额外说明

  • 若android:fitsSystemWindows="true"在BottomNavigationView上不生效,可替换为android:layout_marginBottom="?android:attr/navigationBarHeight",直接预留系统导航栏高度
  • 确保Activity主题未设置android:windowTranslucentNavigation="true",该属性会导致系统导航栏透明,布局会延伸至导航栏下方

内容的提问来源于stack exchange,提问作者Tamir Yosef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:15:03