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

Android Java开发中引入Fragment后Bottom navigation bar不显示问题

问题根源

你当前activity_main.xml的配置存在错误:将承载Fragment的容器IDfragment_container直接绑定到了根布局RelativeLayout上,执行Fragment替换逻辑时,Fragment的全屏布局会直接填充整个根视图,自然覆盖了写在根布局内部的底部导航栏。

修复方案

1. 调整activity_main.xml布局

单独新增Fragment容器控件,设置其位于底部导航栏上方,修改后代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".User.Main"
    android:background="#eeeeee">

    <!-- 单独新增的Fragment容器,位于导航栏上方 -->
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_nav_menu"/>

    <com.ismaeldivita.chipnavigation.ChipNavigationBar
        android:id="@+id/bottom_nav_menu"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:background="@color/white"
        app:cnb_unselectedColor="@color/black"
        app:cnb_radius="8dp"
        app:cnb_menuResource="@menu/bottom_navigation_menu"/>

</RelativeLayout>

2. 修复代码笔误

你贴出的HomeFragment.java(你笔误写为HomeFragment.xml)末尾多了一个无关字符v,请删除后再编译,避免语法报错。

内容的提问来源于stack exchange,提问作者Joseph Wamulume

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 00:54:06