Cosimo Sguanci
Cosimo Sguanci

Reputation: 1291

Programmatically change menu icon color in Toolbar

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.

Upvotes: 2

Views: 9981

Answers (1)

Charuka Silva
Charuka Silva

Reputation: 13153

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);

Upvotes: 6

Related Questions