BottomNavigationView Original icon color

人盡茶涼 提交于 2019-11-27 18:03:15

问题


I have my bottomNavigationView :

And i added this class to prevent it from doing shiftingMode :

public class BottomNavigationViewHelper {
    public static void disableShiftMode(BottomNavigationView view) {
        BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
        try {
            Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
            shiftingMode.setAccessible(true);
            shiftingMode.setBoolean(menuView, false);
            shiftingMode.setAccessible(false);
            for (int i = 0; i < menuView.getChildCount(); i++) {
                BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
                //noinspection RestrictedApi
                item.setShiftingMode(false);
                // set once again checked value, so view will be updated
                //noinspection RestrictedApi
                //item.setChecked(item.getItemData().isChecked());
            }
        } catch (NoSuchFieldException e) {
            Log.e("BNVHelper", "Unable to get shift mode field", e);
        } catch (IllegalAccessException e) {
            Log.e("BNVHelper", "Unable to change value of shift mode", e);
        }
    }

I just want to show the original icons colors without this selector, how i can reach this ?

my navigation xml :

<android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/my_navigation_item"
        android:layout_alignParentBottom="true"/>

回答1:


You have to make your item icon tint list null, You reach that from your bootomNav :

bottomNavigationView.setItemIconTintList(null);



回答2:


Here How you would do if you are using Kotlin Find your navigation Id From your Main Activity then in your mainActivity onCreat Use This Code

 my_navigation_item.itemIconTintList = null



回答3:


You are able to use app:itemIconTint from xmlns:app="http://schemas.android.com/apk/res-auto"

For example

<android.support.design.widget.BottomNavigationView
    //...
    app:itemIconTint="@color/gray_scale"
    //...
/>

It is handy when your drawables have different colors



来源:https://stackoverflow.com/questions/44515664/bottomnavigationview-original-icon-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!