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
  • 483
  • 8
  • 18

4 Answers4

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
  • 4,992
  • 5
  • 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

Hope this helps,as it worked for me.

Drawable myDrawable = context.getResources().getDrawable(R.drawable.menu); 
mDrawable.setColorFilter(new 
PorterDuffColorFilter(0xffff00,PorterDuff.Mode.MULTIPLY));
Niroj
  • 1,146
  • 6
  • 28
  • I use default menu icon. Can I get it from @android:drawable? I don't want use custome icon – Ossir Aug 16 '16 at 12:23
  • You can paste this in your mainActivity. This might be the solution to you. //set the drawable image ic_menu to open drawable in action bar. final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeAsUpIndicator(R.drawable.ic_menu); actionBar.setDisplayHomeAsUpEnabled(true); – Niroj Aug 16 '16 at 15:18
-1

Link 1 (Recommended)

Link 2

Just follow the instructions from either of these links. Your Problem will be solved.

Community
  • 1
  • 1
  • Please avoid posting only external links. A **good answer** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. – B001ᛦ Aug 16 '16 at 12:43
  • 1
    Ok i will keep in mind next time i answer someone. Thanks for letting me know – Deathracer 4991 Aug 19 '16 at 04:39
-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