底部导航栏图标无法显示原始设计颜色问题求助
Android底部导航栏图标无法显示原始多色问题
问题描述
- 主活动中已实现底部导航栏,配置4个图标:部分为橙色系,1个图标包含洋红+橙色双配色
- 图标显示异常:未激活时为深灰色,激活时为黑色,无法呈现自身的多色设计
- 尝试设置
app:itemIconTint="@null"后,图标会继承themes.xml中定义的颜色;未配置主题颜色时,图标显示为淡紫色
解决办法
1. 代码层面强制取消着色
在主活动的onCreate方法中添加代码,直接清空图标着色列表:
// Kotlin写法 findViewById<BottomNavigationView>(R.id.bottom_nav).apply { itemIconTintList = null }
// Java写法 BottomNavigationView bottomNav = findViewById(R.id.bottom_nav); bottomNav.setItemIconTintList(null);
2. 布局+Vector图标兼容配置
- 确保Vector图标放在
res/drawable目录,menu文件中直接用@drawable/xxx引用图标 - 底部导航栏布局中明确设置取消着色:
<com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_nav" android:layout_width="match_parent" android:layout_height="wrap_content" app:menu="@menu/menu_yo" app:itemIconTint="@null" />
- 在
AndroidManifest.xml的<application>标签中开启硬件加速,避免Vector图标渲染异常:
<application ... android:hardwareAccelerated="true">
3. 排查主题默认着色
检查themes.xml中是否存在全局图标着色配置,若有则移除或针对性覆盖:
<!-- 若存在以下属性,可删除或修改为@null --> <item name="iconTint">@color/xxx</item>
内容的提问来源于stack exchange,提问作者user24097535
相关产品推荐
相关产品推荐

