以编程方式更改工具栏中的菜单图标颜色
Programmatically change menu icon color in Toolbar
我开发了一个应用程序,用户可以在其中更改主题。我有一个导航视图,工具栏中有一个黑色的菜单图标。
我想更改该图标,使其变为白色(在黑色主题上)。我试过这段代码,但它仍然是黑色的:
myToolbar.setTitleTextColor(Color.WHITE);
ab.setHomeAsUpIndicator(R.mipmap.ic_menu_white_24dp); //ab=ActionBar
ab.setDisplayHomeAsUpEnabled(true);
标题变成白色,但图标没有改变。
1.Add 带有您喜欢的颜色的全新图标ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_new);
2.Use 这个要染色
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu, null);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.WHITE);
ab.setHomeAsUpIndicator(drawable);
我开发了一个应用程序,用户可以在其中更改主题。我有一个导航视图,工具栏中有一个黑色的菜单图标。
我想更改该图标,使其变为白色(在黑色主题上)。我试过这段代码,但它仍然是黑色的:
myToolbar.setTitleTextColor(Color.WHITE);
ab.setHomeAsUpIndicator(R.mipmap.ic_menu_white_24dp); //ab=ActionBar
ab.setDisplayHomeAsUpEnabled(true);
标题变成白色,但图标没有改变。
1.Add 带有您喜欢的颜色的全新图标ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_new);
2.Use 这个要染色
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu, null);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.WHITE);
ab.setHomeAsUpIndicator(drawable);