I want to change color of burger/arrow icon of navigation drawer. I know I can change it in styles, but I want change it dynamically in java. Did anybody know how to do this?
Asked
Active
Viewed 2,455 times
3
-
What code is not working? – moffeltje Aug 26 '15 at 14:06
-
have same problem here. and @moffeltje guess Rafal have no lucky looking for code for it (same here).. it's been 3 hours looking for it. – MiguelHincapieC Sep 11 '15 at 17:00
-
Rafal if you found an answer, can you post it or work around for it? – MiguelHincapieC Sep 11 '15 at 17:03
-
No i dont found how to do this, only way to colorize that icon is change theme in resource:/ – Rafal Ulko Sep 14 '15 at 07:00
-
I got it, I'm trying to change all elements of toolbar dynamically. I'm missing right now ActionMenuViews [look at my question](http://stackoverflow.com/questions/32569989/change-drawer-burger-arrow-icon-dynamically-without-styling-toolbar). – MiguelHincapieC Sep 16 '15 at 20:53
2 Answers
10
Using appcompat-v7:23.0.1 next code worked for me:
int color = Color.parseColor("#FFEEEE00");
final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
for (int i = 0; i < toolbar.getChildCount(); i++) {
final View v = toolbar.getChildAt(i);
if (v instanceof ImageButton) {
((ImageButton) v).setColorFilter(colorFilter);
}
}
Use it in public boolean onCreateOptionsMenu(Menu menu)

MiguelHincapieC
- 5,445
- 7
- 41
- 72
-
Did find it useful for you?, do you need something else or its fine. [Remember to accept the correct answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) – MiguelHincapieC Sep 17 '15 at 15:09
-
This works, thanks. And needs to be set in onCreateOptionsMenu, otherwise it doesnt work. At least for me. – Zokran Jan 11 '16 at 10:36
0
You can use setTint
of the new DrawableCompat
class (from support v4 lib)
// Get the icon you want as a drawable
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu, null);
// "Enable" tinting process
drawable = DrawableCompat.wrap(drawable);
// Tint it
DrawableCompat.setTint(drawable, Color.BLACK);
// Set it as action bar icon
actionBar.setHomeAsUpIndicator(drawable);
For more details about drawable tinting see Chris Bane post about support lib V22.1

Gaëtan Maisse
- 12,208
- 9
- 44
- 47