BottomNavigationBar 图片颜色被改变

问题:当使用setActiveColorResource
,设置选中颜色的时候,图片的颜色被改变了。

解决:找到BottomNavigationTab
类,继续找到 public void initialise(boolean setActiveColor)
方法。

 public void initialise(boolean setActiveColor) {
        iconView.setSelected(false);
        if (isInActiveIconSet) {
            StateListDrawable states = new StateListDrawable();
            states.addState(new int[]{android.R.attr.state_selected},
                    mCompactIcon);
            states.addState(new int[]{-android.R.attr.state_selected},
                    mCompactInActiveIcon);
            states.addState(new int[]{},
                    mCompactInActiveIcon);
            iconView.setImageDrawable(states);
        } else {
            if (setActiveColor) {
//                DrawableCompat.setTintList(mCompactIcon, new ColorStateList(
//                        new int[][]{
//                                new int[]{android.R.attr.state_selected}, //1
//                                new int[]{-android.R.attr.state_selected}, //2
//                                new int[]{}
//                        },
//                        new int[]{
//                                mActiveColor, //1
//                                mInActiveColor, //2
//                                mInActiveColor //3
//                        }
//                ));
            } else {
                DrawableCompat.setTintList(mCompactIcon, new ColorStateList(
                        new int[][]{
                                new int[]{android.R.attr.state_selected}, //1
                                new int[]{-android.R.attr.state_selected}, //2
                                new int[]{}
                        },
                        new int[]{
                                mBackgroundColor, //1
                                mInActiveColor, //2
                                mInActiveColor //3
                        }
                ));
            }
            iconView.setImageDrawable(mCompactIcon);
        }

        if (isNoTitleMode) {
            labelView.setVisibility(GONE);

            LayoutParams layoutParams = (LayoutParams) iconContainerView.getLayoutParams();
            layoutParams.gravity = Gravity.CENTER;
            setNoTitleIconContainerParams(layoutParams);
            iconContainerView.setLayoutParams(layoutParams);

            LayoutParams iconLayoutParams = (LayoutParams) iconView.getLayoutParams();
            setNoTitleIconParams(iconLayoutParams);
            iconView.setLayoutParams(iconLayoutParams);
        }
    }

注释 setActiveColor 这个条件的代码

你可能感兴趣的:(Android)