【问题标题】:How to change BottomNavigationBar icons on click?如何在点击时更改 BottomNavigationBar 图标?
【发布时间】:2017-07-12 05:59:39
【问题描述】:

有没有办法在底部导航视图上单击图标时更改图标?我尝试使用这样的选择器,但它不起作用,或者我只是不知道如何实现它。

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

<item android:drawable="@drawable/like" android:state_checked="true"/>
<item android:drawable="@drawable/like2" android:state_checked="false"/>

<item android:drawable="@drawable/play" android:state_checked="true"/>
<item android:drawable="@drawable/play2" android:state_checked="false"/>

<item android:drawable="@drawable/alarm" android:state_checked="true"/>
<item android:drawable="@drawable/alarm2" android:state_checked="false"/>

<item android:drawable="@drawable/user" android:state_checked="true"/>
<item android:drawable="@drawable/user2" android:state_checked="false"/>
</selector>

喜欢这个

【问题讨论】:

    标签: android android-layout android-fragments material-design bottomnavigationview


    【解决方案1】:

    您需要为每张图片制作一个选择器。 所以你的home_selector.xml 将是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      相关资源
      最近更新 更多