Toolbar Navigation Hamburger Icon missing - android
I'm looking for a way to display the hamburger icon whitout using the Drawer/DrawerToggle and use the default icon included in Android
By setting getSupportActionBar().setDisplayHomeAsUpEnabled(true); it display the back arrow but not the hambuerger. Other post on Stackoverflow (like this or this) use the DrawerLayout or a custom drawable. I cannot find the vector or png for the hamburger icon on the Android source.
Do you know how can I find the original hamburger icon in android/support library? (or how to displayed it)
Note: Vector and png can be found on google.com/design website : http://www.google.com/design/spec/resources/sticker-sheets-icons.html#
In my activity
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(LOG_TAG, "navigation clicked");
}
});
Layout file
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar"/>
Styles.xml
<!-- Base application theme. -->
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primaryDef</item>
<item name="colorPrimaryDark">#color/primaryDarkDef</item>
<item name="colorAccent">#color/primaryDef</item>
<!-- Remove the actionbar shadow-->
<item name="android:windowContentOverlay">#null</item>
</style>
If you want to use the same drawer as lollipop then let me tell you that's not a static image. That image is drawn in real time by a class called DrawerArrowDrawableToggle. So there is no "hamburger" icon for that.
However if you want the hamburger icon with no animation you can find it here:
https://material.io/tools/icons/?icon=menu&style=baseline
To have an animated hamburger icon you should use DrawerLayout with ActionBarDrawerToggle and enable the icon for the ActionBar and for the ActionBarDrawerToggle.
Example:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle mDrawerToggle;
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
{
actionBar.setDisplayHomeAsUpEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.hello_world, R.string.hello_world)
{
public void onDrawerClosed(View view)
{
supportInvalidateOptionsMenu();
//drawerOpened = false;
}
public void onDrawerOpened(View drawerView)
{
supportInvalidateOptionsMenu();
//drawerOpened = true;
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
}
Also, you need to add these methods to your Activity:
#Override
protected void onPostCreate(Bundle savedInstanceState)
{
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
For that you just need write to some lines
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(true);
toggle.syncState();
toggle.setDrawerIndicatorEnabled(true); if this is false make it true or remove this line
Here is the simplest solution that worked for me.
The ActionBarDrawerToggle has two types constructors. One of them take toolbar as a parameter. Use that (second one below) to get the animated hamburger.
ActionBarDrawerToggle(this, mDrawerLayout, R.string.content_desc_drawer_open,
R.string.content_desc_drawer_close);
ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.content_desc_drawer_open,
R.string.content_desc_drawer_close);` //use this constructor
You can try to make your own drawable for the hamburger icon like this.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#ffffff"
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z" />
</vector>
Then in your fragment/activity,
getSupportActionBar().setHomeAsUpIndicator(R.drawable.as_above);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
For other drawables, this might help: https://github.com/google/material-design-icons/blob/master/navigation/drawable-anydpi-v21/
I had the same problem and I found the simplest solution here:
appcompatv7-v21-navigation-drawer-not-showing-hamburger-icon
All I had to do was to call:
mDrawerToggle.syncState();
I had the same problem.
Get the ToolBar and then set Navigation icon
final android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.blablabla);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle("title");
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_list);
ok to hide back arrow use
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);
then find hamburger icon in web ->hamburger
and finally, set this drawable in your project with action bar method:
getSupportActionBar().setLogo(R.drawable.hamburger_icon);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
it's work with me
Maybe you can try this, but you will lose animation between arrow and hamburger icon
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
super.setContentView(R.layout.activity_menu_drawer_left);
_drawerToggle = new ActionBarDrawerToggle(this, _drawerLayout, R.string.drawer_opened, R.string.drawer_closed) {
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
changeDrawerIconOnDrawerClick(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
changeDrawerIconOnDrawerClick(R.drawable.ic_drawer);
}
};
//to change default icon to hamburger item initially
changeDrawerIconOnDrawerClick(R.drawable.ic_drawer); }
private void changeDrawerIconOnDrawerClick(int resourceId) {
//Drawable icon = ContextCompat.getDrawable(getApplicationContext(), resourceId);
Drawable icon = ResourcesCompat.getDrawable(getResources(), resourceId, null);
icon.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
_drawerToggle.setDrawerIndicatorEnabled(false);
_drawerToggle.setHomeAsUpIndicator(icon);
}
Replace the default Up-arrow with your own drawable
getSupportActionBar().setHomeAsUpIndicator(R.drawable.hamburger);
Just Add the following in your onCreate method,
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, mToolbar, R.string.home_navigation_drawer_open, R.string.home_navigation_drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
}
};
mDrawer.addDrawerListener(toggle);
toggle.syncState();
and In strings.xml,
<string name="home_navigation_drawer_open">Open navigation drawer</string>
<string name="home_navigation_drawer_close">Close navigation drawer</string>
Use this constructor in MyActionBarDrawerToggle :
public MyActionBarDrawerToggle(AppCompatActivity host, DrawerLayout drawerlayout, SupportToolbar toolbar, int openedResource, int closedResource)
: base(host, drawerlayout, toolbar, openedResource, closedResource)
{
mHostActivity = host;
mOpenedResource = openedResource;
mClosedResource = closedResource;
}
and Call this method in teh mainActivity (Using AppCompatActivity)
mDrawerToggle = new MyActionBarDrawerToggle(
this, //Host Activity
mDrawerLayout, //DrawerLayout
mToolbar, //Toolbar
Resource.String.openDrawer, //Opened Message
Resource.String.closeDrawer //Closed Message
);
mDrawerLayout.AddDrawerListener(mDrawerToggle);
SupportActionBar.SetHomeButtonEnabled(true);
SupportActionBar.SetDisplayShowTitleEnabled(true);
mDrawerToggle.DrawerIndicatorEnabled = true;
mDrawerToggle.SyncState();
in onCreate():
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close) {
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
supportInvalidateOptionsMenu();
}
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
supportInvalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(drawerToggle);
drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Backstack.get(MainActivity.this).goBack();
}
});
//actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
//getSupportActionBar().setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(true);
And when setting up UP navigation:
private void setupViewsForKey(Key key) {
if(key.shouldShowUp()) {
drawerToggle.setDrawerIndicatorEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
else {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
drawerToggle.setDrawerIndicatorEnabled(true);
}
drawerToggle.syncState();
in JetPack it work for me
NavigationUI.setupWithNavController(vb.toolbar, nav)
vb.toolbar.navigationIcon = ResourcesCompat.getDrawable(resources, R.drawable.icon_home, null)
Related
Android navigationView when is visible on screen listener
Is there a listener for navigationView if it is actived (Is visible on screen)? I tried setonsystemuivisibility but not works. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); I need listener to be called when it's on screen and when it's gone. thanks.
Add a DrawerListener: mDrawerLayout = findViewById(R.id.drawer_layout); mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { // other overridden methods not shown #Override public void onDrawerOpened(View drawerView) { // drawer opened // todo: announce for accessibility } });
Hope This will help you DrawerLayout mDrawerLayout; public static ActionBarDrawerToggle mDrawerToggle; mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(FragmentHomeActivity.this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name){ public void onDrawerClosed(View view) { //calling onDrawerClosed, when View gone invisible } public void onDrawerOpened(View drawerView) { // calling onDrawerOpened, when View visible } }; mDrawerLayout.setDrawerListener(mDrawerToggle); If you are using Toolbar, then toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);
Android - Navigation Drawer change action bar icon
I have action bar with one icon: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="#+id/is_connected" android:icon="#drawable/ic_disconnected" android:title="#string/general_disconnected" app:showAsAction="always"/> When I change that icon in this way: mActionBarMenu.getItem(0).setIcon(getResources().getDrawable(R.drawable.ic_connected)); and open navigation drawer that that item icon change to initial state ang again is: #drawable/ic_disconnected It is possible to avoid that? UPDATE: private void setupDrawer() { mDrawerList = (ListView) findViewById(R.id.navList); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mActivityTitle = getTitle().toString(); addDrawerItem(); mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); //getSupportActionBar().setTitle("Menu"); invalidateOptionsMenu(); } /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); } }; mDrawerLayout.post(new Runnable() { #Override public void run() { mDrawerToggle.syncState(); } }); mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); }
How to set drawer toggle icon (`hamburger`) for the ActionBarDrawerToggle v7 without toolbars
I'm using action bar from android.support.v7.app.ActionBarActivity so my activity is declared like this: public class MyActivity extends ActionBarActivity { I'm reading the tutorial which shows how to add Drawer: DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); This is for the import android.support.v4.app.ActionBarDrawerToggle. Now I've decided to use v7 since v4 is deprecated, but the constructor for the v7 doesn't accept icon for the drawer. I've googled and found that the solution is to use the constructor flavor that accepts toolbar: ActionBarDrawerToggle(this, drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) but I don't use toolbars. So I don't understand how I can set icon with v7 without toolbars. Should I switch to using Toolbars?
Hey you get the solution here.. private Toolbar toolbar; toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); toolbar.setNavigationIcon(R.drawable.ic_drawer); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } This one is also a good approach, personally i use this one. public class MyActionBarDrawerToggle extends android.support.v7.app.ActionBarDrawerToggle { public MyActionBarDrawerToggle(Activity activity, final DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) { super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes); setHomeAsUpIndicator(R.drawable.drawer_toggle); setDrawerIndicatorEnabled(false); setToolbarNavigationClickListener(new View.OnClickListener() { #Override public void onClick(View view) { drawerLayout.openDrawer(Gravity.LEFT); } }); } } Thank you.
ActionToggle image not showing
I am implementing ActionTogglebutton to show drawer.though drawer are showing on click of toggle button but image or nothing is shown on toggle button position Here is my code actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.drawable.kooveicon) { public void onDrawerClosed(View view) { getActionBar().setTitle(getTitle()); getActionBar().setDisplayShowHomeEnabled(false); getActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setTitle("Closed"); invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setTitle("Browse Items"); invalidateOptionsMenu(); } };
Update your code exactly like below: actionBar = getSupportActionBar(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close); mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerLayout.setDrawerListener(mDrawerToggle); and add another method onPostCreate() in your class [this is drawer indicator animation] #Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); mDrawerToggle.syncState(); } Hope this helped!
How to replace the hamburger icon used for ActionBarToggle on Android Toolbar with a custom drawable?
I have implemented a basic ActionBarDrawerToggle using the new Toolbar in Android 5.0. However, I am unable to figure out how to change the default hamburger icon that is supplied. From the android documentation it says that "the given Activity will be linked to the specified DrawerLayout and the Toolbar's navigation icon will be set to a custom drawable... This drawable shows a Hamburger icon when drawer is closed and an arrow when drawer is open. It animates between these two states as the drawer opens." I currently have this all working correctly with the following code, however I want to replace the default supplied hamburger with my own drawable. Here is my current code: MainActivity.java #InjectView(R.id.main_activity_toolbar) Toolbar mToolbar; #InjectView(R.id.main_activity_drawer_layout) DrawerLayout mDrawerLayout; #Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.main_activity); super.onCreate(savedInstanceState); setSupportActionBar(mToolbar); mToolbar.setNavigationIcon(R.drawable.navigation); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } This line: mToolbar.setNavigationIcon(R.drawable.navigation); doesn't seem to work. Is this possible to do? Thanks! ActionBarToggle Documentation - https://developer.android.com/reference/android/support/v7/app/ActionBarDrawerToggle.html
You can use the toolbar as Stand Alone mode, that means you should not use your toolbar as part of your ActionBarDrawerToggle constructor, you can achieve that using the below code: mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, null, R.drawable.appbar, R.drawable.appbar) (Note how the toolbar instance is not being sent to the ActionBarDrawerToggle constructor) Also, you should inflate your menu manually mToolbar = (Toolbar) findViewById(R.id.nav_toolbar); mToolbar.inflateMenu(R.menu.base); And remove the setSupportActionBar(mToolbar); line of code. Of course, you will have to handle the navigation click by yourself: mToolbar.setOnMenuItemClickListener(new OnMenuItemClickListener() ... Then, you can open your drawer like this: drawerButton = (BadgeDrawerButton) findViewById(R.id.badge_drawer_button); drawerButton.setOnClickListener( new View.OnClickListener() { #Override public void onClick(View v) { mDrawerLayout.openDrawer(Gravity.LEFT); } }); Hope this may help.
These two lines of code work for me: mDrawerToggle.setDrawerIndicatorEnabled(false); //disable "hamburger to arrow" drawable mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); //set your own And then call this: mDrawerToggle.syncState();
The default menu drawable for the ActionBarDrawerToggle is DrawerArrowDrawable. You can subclass this to add custom functionality, like badges, like so: public class BadgedDrawerArrowDrawable extends DrawerArrowDrawable { /** * #param context used to get the configuration for the drawable from */ public BadgedDrawerArrowDrawable(Context context) { super(context); setColor(context.getResources().getColor(R.color.colorAccent)); } #Override public void draw(Canvas canvas) { super.draw(canvas); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setTextSize(60); canvas.drawText("!", canvas.getWidth() - 60, 25, paint); } } Usage: actionBarDrawerToggle.setDrawerArrowDrawable(new BadgedDrawerArrowDrawable(activity));
My solution is by subclassing ActionBarDrawerToggle. public class MyActionBarDrawerToggle extends android.support.v7.app.ActionBarDrawerToggle { public MyActionBarDrawerToggle(Activity activity, final DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) { super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes); setHomeAsUpIndicator(R.drawable.drawer_toggle); setDrawerIndicatorEnabled(false); setToolbarNavigationClickListener(new View.OnClickListener() { #Override public void onClick(View view) { drawerLayout.openDrawer(Gravity.LEFT); } }); } }
the thing that worked for me is that i just needed to call toolbar.setNavigationIcon(R.drawable.ic_camera_alt_24dp); at the end of onCreate, or at least after mDrawerToggle = new ActionBarDrawerToggle...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); toolbar.setNavigationIcon(R.drawable.ic_action_name);
as of Jan 2018, this is a working solution (at least for me): //setSupportActionBar(toolbar) val toggle = ActionBarDrawerToggle(this, drawer_layout, null, R.string.navigation_drawer_open, R.string.navigation_drawer_close) toolbar.inflateMenu(R.menu.menu_main) toolbar.setNavigationIcon(R.drawable.ic_menu) toolbar.setNavigationOnClickListener { drawer_layout.openDrawer(Gravity.START) } toolbar.setOnMenuItemClickListener { true } drawer_layout.addDrawerListener(toggle) toggle.syncState() nav_view.setNavigationItemSelectedListener(this) things to care: setSupportActionBar should be commented out ActionBarDrawerToggle is not taking a reference to toolbar We should inflate menu ourself, and handle onClicks. onCreateOptionsMenu and onOptionsItemSelected will not be functioning. Don't forget to call toggle.syncState()
As for v7 support library - you can create your own representation of DrawerArrowDrawable. mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { public void onDrawerClosed(View view) { supportInvalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { supportInvalidateOptionsMenu(); } }; mDrawerToggle.setDrawerIndicatorEnabled(true); DrawerArrowDrawable drawerArrowDrawable = new DrawerArrowDrawable(this); drawerArrowDrawable.setAlpha(1); drawerArrowDrawable.setSpinEnabled(false); drawerArrowDrawable.setDirection(DrawerArrowDrawable.ARROW_DIRECTION_LEFT); drawerArrowDrawable.setColor(Color.BLACK); mDrawerToggle.setDrawerArrowDrawable(drawerArrowDrawable);
Here's how I was able to finally get mine to work. private Toolbar toolbar; toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); toolbar.setNavigationIcon(R.drawable.ic_drawer); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } It turned out to be the mDrawerToggle.syncState(); That finally got everything to work.
I think it is recommended to put the call to syncState() in the onPostCreate(...) lifecycle method. #Override public void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); mDrawerToggle.syncState(); }