如何在選擇和取消選擇時更改底部導航圖示這是我以前的代碼
bottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.bottom_tabs));
bottomBar.setActiveTabColor("#FFFFFE");
uj5u.com熱心網友回復:
首先你必須在你的drawable檔案夾中使drawable可選
<?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>
在底部導航選單中,將此可選擇的可繪制物件放置為圖示
<?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>
在您使用底部導航的活動或片段中,使用以下行
bottomNavigationView.itemIconTintList = null
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/464283.html
下一篇:將XML子元素決議為字串
