Programmatically change menu icon color in Toolbar

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 15:29:43

问题


I've developed an App, where the user can change the theme. I have a navigation view, with a menu icon in Toolbar that is black.

I would like to change that icon, to have it white (on a black theme). I tried this code but it remained black:

myToolbar.setTitleTextColor(Color.WHITE);
ab.setHomeAsUpIndicator(R.mipmap.ic_menu_white_24dp); //ab=ActionBar
ab.setDisplayHomeAsUpEnabled(true);

The title becomes White, but the icon doesn't change.


回答1:


1.Add a completely new icon with your favorite color ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_new);

2.Use this to tint

    Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu, null);
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, Color.WHITE);
    ab.setHomeAsUpIndicator(drawable);


来源:https://stackoverflow.com/questions/41317428/programmatically-change-menu-icon-color-in-toolbar

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