【问题标题】:Change Android BottomBar Icon on Select在选择上更改 Android BottomBar 图标
【发布时间】:2017-01-03 19:43:38
【问题描述】:

有没有一种简单的方法可以更改 Android BottomBar 导航 (https://github.com/roughike/BottomBar) 的图标。我见过很多方法来设置这个图标,但我想在用户选择它时更改图标。目前我有一个带有轮廓的图标,我想在他们选择它时显示一个填充图标。任何帮助都会很棒。

【问题讨论】:

    标签: android android-navigation bottombar


    【解决方案1】:

    看起来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

    【讨论】:

      【解决方案2】:

      源文件中的iconResId 似乎有一个getter 和setter。
      你试过了吗?

      创建一个 BottomBarTab() 对象,并在 OnItemSelected 中使用您想要的图标选择调用此 setter 方法。 https://github.com/roughike/BottomBar/blob/master/bottom-bar/src/main/java/com/roughike/bottombar/BottomBarTab.java#L175

      【讨论】:

      • 嗯,这很奇怪。我建议在 github 上打开一个问题,因为作者会知道最好的方法是什么。
      • 我做到了。大声笑...我希望很快能收到回复。
      猜你喜欢
      • 1970-01-01
      • 2016-09-28
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 2019-01-10
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多