我需要更改菜单图标的颜色,我尝试了许多发现的方法,但是其中一种方法不起作用
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);
,请帮助我
使用itemIconTint
属性来更改NavigationView项目图标的颜色。
<com.google.android.material.navigation.NavigationView
app:itemIconTint="@color/colorPrimary" />