如何在 Select 和取消 Select 时更改底部导航图标

bottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.bottom_tabs));
bottomBar.setActiveTabColor("#FFFFFE");

推荐答案

First you have to make drawable selectable in your drawable folder

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/selected_icon"/>
    <item android:state_selected="false" android:drawable="@drawable/unselected_icon" />
    <item android:drawable="@drawable/unselected_icon" />
</selector>

In the bottom navigation menu place this selectable drawable as icon

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/itemId"
        android:icon="@drawable/drawable_selectable_name"
        android:title="@string/title"/>
</menu>

In activity or fragment where you have used bottom navigation use the following line

bottomNavigationView.itemIconTintList = null

Java相关问答推荐

为什么如果数组列表中有重复项,我的代码SOMETIMES不返回true?

在spring—data中自动发现native—sql查询期间遇到重复的SQL别名[id]

Junit with Mockito for java

使用Mockito进行的Junit测试失败

呈现文本和四舍五入矩形时出现的JavaFX窗格白色瑕疵

具有阻塞方法的开源库是否应该为执行提供异步选项?

try 判断可选参数是否为空时出现空类型安全警告

有效的公式或值列表必须少于或等于255个字符

Java泛型类方法的静态返回类型是否被类型擦除?

在处理2个映射表时,没有更多的数据可从套接字读取

如何使用MapStrCut转换双向链接

视图被推出线性布局-Android

如何从命令行编译包中的所有类?

处理4.3问题:javax.xml.ind包不存在(&Q;).您可能在学习GitHub教程时遗漏了库.&Q

不能在 map 上移除折线

如何通过用户ID向用户发送私信

如何使用jOOQ在PostgreSQL中从枚举类型生成Java枚举

没有Google Play服务,Firebase Auth无法工作

如何判断元素计数并在流的中间抛出异常?

ResponseEntity.控制器截断响应的JSON部分