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

如何禁用BottomNavigationView默认背光?自定义背光后仍有粉色高亮

解决BottomNavigationView默认粉色高亮问题

以下几种方法可以帮你移除默认的粉色高亮效果:

方法一:直接禁用波纹高亮

在你的BottomNavigationView布局中添加app:itemRippleColor属性,设置为透明色,彻底去掉默认的波纹高亮:

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/bottom_nav_background"
        app:itemIconTint="@drawable/nav_item_color"
        app:itemTextColor="@drawable/nav_item_color"
        app:itemBackground="@drawable/nav_item_background"
        app:itemRippleColor="@android:color/transparent" <!-- 添加这行 -->
        app:labelVisibilityMode="labeled"
        style="@style/BottomNavigationStyle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation" />

方法二:检查自定义itemBackground的Selector

默认高亮可能是因为你的@drawable/nav_item_background没有正确定义选中态样式,系统自动使用了主题的默认颜色。确保这个drawable是包含选中/未选中状态的Selector:

<!-- res/drawable/nav_item_background.xml -->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 选中时使用你的自定义背光效果 -->
    <item android:drawable="@drawable/your_custom_selected_bg" android:state_checked="true"/>
    <!-- 未选中时设为透明或你需要的背景 -->
    <item android:drawable="@android:color/transparent"/>
</selector>

方法三:修改自定义样式BottomNavigationStyle

如果你的@style/BottomNavigationStyle继承了Material默认样式,可能会继承主题的粉色高亮,在style中覆盖相关属性:

<!-- res/values/styles.xml -->
<style name="BottomNavigationStyle" parent="Widget.MaterialComponents.BottomNavigationView">
    <!-- 禁用波纹 -->
    <item name="itemRippleColor">@android:color/transparent</item>
    <!-- 指定自定义的item背景 -->
    <item name="itemBackground">@drawable/nav_item_background</item>
    <!-- 若主题的colorPrimary是粉色,可在这里覆盖为你需要的颜色 -->
    <item name="colorPrimary">@color/your_custom_color</item>
</style>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.01 20:43:07