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

如何禁用Android Studio中底部导航菜单选中项的放大效果

Android 底部导航选中项图标放大问题解决方案

你遇到的问题效果如下图所示:
底部导航菜单选中项放大示例
这是BottomNavigationView默认的选中态缩放动画,可通过以下方案取消缩放,让所有导航项图标尺寸保持一致:


解决方案

方法1:XML布局直接配置(最常用)

在布局文件的BottomNavigationView控件中添加以下属性:

<!-- 统一所有导航项图标尺寸,可根据需求调整数值 -->
app:itemIconSize="24dp"
<!-- 禁用选中项的平移缩放动画 -->
app:itemHorizontalTranslationEnabled="false"
<!-- 可选:如果需要同时统一选中/未选中的文字大小,添加以下两行 -->
app:itemTextAppearanceActive="@style/NavTextNormal"
app:itemTextAppearanceInactive="@style/NavTextNormal"

在res/values/styles.xml中添加统一的文字样式:

<style name="NavTextNormal" parent="TextAppearance.MaterialComponents.BottomNavigationView.Label">
    <item name="android:textSize">12sp</item>
</style>

方法2:代码动态设置

如果需要运行时动态修改,可通过代码调用对应方法:

Kotlin 示例

// 统一设置图标尺寸,R.dimen.nav_icon_size为你提前定义的dp值
bottomNav.itemIconSize = resources.getDimensionPixelSize(R.dimen.nav_icon_size)
// 禁用选中缩放动画
bottomNav.itemHorizontalTranslationEnabled = false

Java 示例

bottomNav.setItemIconSize(getResources().getDimensionPixelSize(R.dimen.nav_icon_size));
bottomNav.setItemHorizontalTranslationEnabled(false);

方法3:旧版本Material组件兼容方案

如果你使用的Material组件库版本低于1.4.0,上述属性不生效的话,可通过自定义样式覆盖默认效果:
在res/values/styles.xml中添加自定义导航样式:

<style name="NoScaleBottomNav" parent="Widget.MaterialComponents.BottomNavigationView">
    <item name="itemIconSize">24dp</item>
    <item name="itemHorizontalTranslationEnabled">false</item>
    <item name="android:scaleType">centerInside</item>
</style>

然后在布局中给BottomNavigationView绑定该样式:

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_nav"
    style="@style/NoScaleBottomNav"
    ... 其他属性 />

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 17:36:02