0

有沒有方法在BottomNavigationView上單擊時更改圖標?我嘗試過使用類似這樣的選擇器,但它不起作用,或者我不知道如何實現它。如何更改點擊BottomNavigationBar圖標?

<?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> 

喜歡這個

enter image description hereenter image description here

回答

0

你需要爲每個圖像的選擇。 因此,您的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>