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

Android Kotlin底部导航选中项图标高亮无法禁用求助

解决Android BottomNavigationView选中项图标高亮问题

方案1:XML布局直接配置

在布局文件的BottomNavigationView标签里添加以下属性,直接移除选中时的背景高亮和点击波纹:

app:itemBackground="@android:color/transparent"
app:itemRippleColor="@android:color/transparent"
  • itemBackground设为透明:去掉选中项图标周围的高亮背景
  • itemRippleColor设为透明:移除点击时的波纹反馈(不需要的话可设置,按需选择)

方案2:Kotlin代码动态设置

如果需要在代码里调整,可添加这段代码:

// 假设你的BottomNavigationView实例是bottomNav
bottomNav.itemBackground = ColorDrawable(Color.TRANSPARENT)
bottomNav.itemRippleColor = ColorStateList.valueOf(Color.TRANSPARENT)

方案3:自定义全局样式

如果多个底部导航都需要这个效果,可在styles.xml中定义统一样式:

<style name="NoHighlightBottomNav" parent="Widget.MaterialComponents.BottomNavigationView">
    <item name="itemBackground">@android:color/transparent</item>
    <item name="itemRippleColor">@android:color/transparent</item>
</style>

然后在布局中引用该样式:

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottomNav"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/NoHighlightBottomNav"
    ... />

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 06:23:12