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

Android BottomNavigationView图标与文字不显示问题排查及解决

问题:BottomNavigationView菜单图标与文字均不显示

我在MainActivity中创建了BottomNavigationView,但菜单图标与文字均不显示。使用Material Library版本1.7.0,先后更换为1.6.1、1.5版本后问题仍存在;尝试Invalidate Caches、Clean Project/Rebuild Project操作也未能解决,真机运行时问题依旧。


相关代码

activity_main.xml

<layout
    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">
    <data>

    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <RelativeLayout
            android:id="@+id/mainActivityBase"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/app_name"
                        android:gravity="center"
                        android:textAppearance="?textAppearanceHeadline4"
                        android:layout_marginTop="25dp"/>

                    <androidx.fragment.app.FragmentContainerView
                        android:id="@+id/nav_host_container"
                        android:name="androidx.navigation.fragment.NavHostFragment"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingBottom="64dp"
                        android:clipToPadding="false"
                        app:defaultNavHost="true"
                        app:navGraph="@navigation/nav_movie_player"
                        tools:layout="@layout/fragment_home" />

                </LinearLayout>

            </androidx.core.widget.NestedScrollView>

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottomNavigationMain"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:layout_alignParentBottom="true"
                android:layout_marginStart="@dimen/marginStart"
                android:layout_marginEnd="@dimen/marginEnd"
                android:layout_marginBottom="@dimen/marginStart"
                android:elevation="8dp"
                app:labelVisibilityMode="unlabeled"
                app:menu="@menu/movie_player_menu"
                app:itemIconSize="28dp"
                app:itemRippleColor="@android:color/transparent"
                />

        </RelativeLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

movie_player_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/homeFragment"
        android:title="@string/home"
        android:icon="@drawable/ic_round_home_24" />

    <item android:id="@+id/searchFragment"
        android:title="@string/search"
        android:icon="@drawable/ic_round_search_24" />

    <item android:id="@+id/profileFragment"
        android:title="@string/profile"
        android:icon="@drawable/ic_round_person_24" />

</menu>
private lateinit var navController: NavController
private lateinit var appBarConfiguration: AppBarConfiguration

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        binding.lifecycleOwner = this

        setupBottomNavigationBar()
    }

private fun setupBottomNavigationBar() {
        val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottomNavigationMain)
        val navHostFragment = supportFragmentManager.findFragmentById(
            R.id.nav_host_container
        ) as NavHostFragment
        navController = navHostFragment.navController

        bottomNavigationView.setupWithNavController(navController)
        appBarConfiguration = AppBarConfiguration(
            setOf(R.id.homeFragment, R.id.searchFragment, R.id.profileFragment)
        )

    }

override fun onSupportNavigateUp(): Boolean {
        return navController.navigateUp(appBarConfiguration)
    }

解决方法

将windowTranslucentNavigation设置为false后问题解决。该属性设为true时,系统导航栏会变为半透明模式,可能导致BottomNavigationView的内容被遮挡或渲染异常,修改为false即可恢复正常显示。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 17:55:20