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

Android底部导航栏图标着色失效问题求助

解决BottomNavigationView图标着色(itemIconTint)无效的问题

核心原因

你当前使用的图标切换选择器中,outline_dashboard_24、baseline_dashboard_24等图标资源本身带有固定颜色,导致BottomNavigationView的itemIconTint无法覆盖原有颜色。而文字颜色不受图标资源属性限制,所以能正常生效。

解决步骤

  1. 调整图标资源底色
    将你的矢量图标(SVG)的填充色/描边色修改为**白色(#FFFFFF)**或透明,确保图标处于"可着色"状态。如果图标本身有固定颜色,tint属性会被直接忽略。

  2. 优化图标切换选择器(可选)
    在图标选择器中显式添加tintMode属性,让BottomNavigationView的tint设置能正常覆盖图标颜色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:drawable="@drawable/outline_dashboard_24" 
        android:state_checked="false"
        android:tintMode="src_in" />
    <item 
        android:drawable="@drawable/baseline_dashboard_24" 
        android:state_checked="true"
        android:tintMode="src_in" />
</selector>

src_in模式会让tint颜色完全覆盖图标原有底色,确保itemIconTint的设置生效。

  1. 代码层面强制设置(可选)
    如果布局设置仍不生效,可在Activity/Fragment中通过代码直接指定图标tint列表:
// Kotlin示例
val bottomNav = findViewById<BottomNavigationView>(R.id.bottomNavigationView)
bottomNav.itemIconTintList = ContextCompat.getColorStateList(this, R.color.buttonBorder)
// Java示例
BottomNavigationView bottomNav = findViewById(R.id.bottomNavigationView);
bottomNav.setItemIconTintList(ContextCompat.getColorStateList(this, R.color.buttonBorder));

验证修改

调整后保留原布局中的app:itemIconTint="@color/buttonBorder"设置,即可看到图标颜色与文字颜色保持一致。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 10:54:58