【发布时间】:2017-01-03 19:43:38
【问题描述】:
有没有一种简单的方法可以更改 Android BottomBar 导航 (https://github.com/roughike/BottomBar) 的图标。我见过很多方法来设置这个图标,但我想在用户选择它时更改图标。目前我有一个带有轮廓的图标,我想在他们选择它时显示一个填充图标。任何帮助都会很棒。
【问题讨论】:
标签: android android-navigation bottombar
有没有一种简单的方法可以更改 Android BottomBar 导航 (https://github.com/roughike/BottomBar) 的图标。我见过很多方法来设置这个图标,但我想在用户选择它时更改图标。目前我有一个带有轮廓的图标,我想在他们选择它时显示一个填充图标。任何帮助都会很棒。
【问题讨论】:
标签: android android-navigation bottombar
看起来BottomBar 的人决定将其合并。他们在 2.2.0 中添加了该功能:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_myicon_selected" android:state_selected="true" />
<item android:drawable="@drawable/ic_myicon_default" android:state_selected="false" />
</selector>
您可以找到参考here。
【讨论】:
源文件中的iconResId 似乎有一个getter 和setter。
你试过了吗?
创建一个 BottomBarTab() 对象,并在 OnItemSelected 中使用您想要的图标选择调用此 setter 方法。 https://github.com/roughike/BottomBar/blob/master/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java#L175
【讨论】: