Как изменить цвет векторного изображения в navigationView - PullRequest
0 голосов
/ 26 января 2020

Мне нужно изменить цвет значка меню , я пробовал много способов, которые нашел, но ни один из них не работает

 navigationView.getMenu().getItem(i).getIcon().setTint(ContextCompat.getColor(context, R.color.colorPrimary));

или

Drawable drawable = navigationView.getMenu().getItem(i).getIcon();
            if(drawable != null) {
                drawable.mutate();
                drawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
                SpannableString s = new SpannableString(name);
                s.setSpan(new ForegroundColorSpan(Current_Theme.getInt("custom_button_arrow",ContextCompat.getColor(context, R.color.custom_button_arrow))), 0, s.length(), 0);
                navigationView.getMenu().getItem(i).setTitle(s);

            }

или

navigationView.getMenu().getItem(i).getIcon().setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);

или

Drawable mWrappedDrawable = drawable.mutate();
                mWrappedDrawable = DrawableCompat.wrap(drawable);
                DrawableCompat.setTint(mWrappedDrawable, Color.RED);
                DrawableCompat.setTintMode(mWrappedDrawable, PorterDuff.Mode.SRC_IN);
navigationView.getMenu().getItem(i).setIcon(mWrappedDrawable);

, пожалуйста, помогите мне

Ответы [ 2 ]

0 голосов
/ 27 января 2020

Я нашел способ

 navigationView.setItemIconTintList(new ColorStateList(new int[][]{ new int[]{android.R.attr.state_enabled} }, new int[] {Color.RED}));
0 голосов
/ 26 января 2020

Используйте свойство itemIconTint для изменения цвета значка элемента NavigationView.

<com.google.android.material.navigation.NavigationView
            app:itemIconTint="@color/colorPrimary" />
...