1

All my fragments use red action bar, so white navigation drawer icon looks good. But for one fragment I need white action bar and drawer icon not visible. So I have to change drawer icon to red. But I can't find how to do this.

How to change icon to red color?enter image description here

Ossir
  • 493
  • 1
  • 8
  • 19

2 Answers2

3

Create style like this for your required activity styles.xml

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@color/red</item>
</style>

And then add it to you Activity theme like this:

<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51
  • This is works but I have one activity and many fragments. Some fragments with red action bar and one with white. If I add this to activity theme drawer icon will be red everywhere not only in fragment with white action bar – Ossir Aug 16 '16 at 12:53
  • You can use this code if you just want to change color with default icon `toolbar.getNavigationIcon().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);` and add this where you adding fragment with desire color in your activity – Burhanuddin Rashid Aug 16 '16 at 13:06
  • `toolbar.getNavigati‌​onIcon()` return null. It return drawble only when I set it manually with `setNavigationIcon` method. But I don't know the name of default menu icon to set it manually. – Ossir Aug 17 '16 at 07:02
  • I have not set any navigation icon.But its working fine in my device – Burhanuddin Rashid Aug 17 '16 at 07:04
  • Put that code after `DrawerLayout` is initialized and created. i.e after navigation listener is set – Burhanuddin Rashid Aug 17 '16 at 07:07
  • It works! When I use this code after `setNavigationItemSelectedListener` it works! Thank you! – Ossir Aug 17 '16 at 07:26
-1

Been trying to do this myself and through trial and error came up with the following

drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
toggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, R.string.open, R.string.close);

int color = getResources().getColor(getResources().getIdentifier("red", "color", getPackageName()));
toggle.getDrawerArrowDrawable().setColor(color);

I prefer this method personally as you can replace "red" with a variable which suited my needs perfectly