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
相关产品推荐
相关产品推荐

