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

Android Studio中BottomNavigationView图标下方空白无法消除求助

解决BottomNavigationView图标下方空白问题

针对BottomNavigationView图标下方存在多余空白的问题,可通过以下两步彻底解决:

  • 添加关键布局属性
    在BottomNavigationView节点中补充两个核心属性,消除文字区域和垂直内边距的预留空间:

    • app:labelVisibilityMode="unlabeled":完全隐藏底部标签文字,移除文字占用的布局空间
    • app:itemVerticalPadding="0dp":清除图标与文字区域的垂直内边距,进一步压缩空白

    修改后的完整布局代码:

    <LinearLayout 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:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        android:orientation="vertical"
        android:padding="0dp"
        tools:context=".dashboard">
    
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="#6000BCD4"
            android:padding="0dp"
            app:itemIconSize="20dp"
            app:itemPaddingBottom="0dp"
            app:itemPaddingTop="0dp"
            app:itemVerticalPadding="0dp"
            app:labelVisibilityMode="unlabeled"
            app:menu="@menu/bottom_nav_value" />
    </LinearLayout>
    
  • 清理menu配置冗余
    打开res/menu/bottom_nav_value.xml,将所有item的android:title设为空字符串,避免系统为文字预留额外空间:

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_home"
            android:title="" />
        <!-- 其他导航item按此格式修改 -->
    </menu>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 02:32:44