The Java – Android hamburger icon is an arrow on 4.x

Android hamburger icon is an arrow on 4.x… here is a solution to the problem.

Android hamburger icon is an arrow on 4.x

I’ve implemented ActionBarDrawerToggle with hamburger icon (supports library v7), but for some reason the toggle only shows the “back” arrow on devices that aren’t running 5.0 (I’ve confirmed this for all 4.x versions). Is this normal behavior?

The arrow looks like this:

The arrow

Now the arrow icon has not changed. The same goes for pulling out drawers for navigation or when in collapsed mode.

This is how I initialize drawertoggle etc.

// drawer toggle
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
        R.string.drawer_open, R.string.drawer_close);
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

edit

To clarify. I’m using the old regular ActionBar, not the toolbar. The hamburger icon appears on 5.0 devices, but not on < 5.0. Should I use the toolbar to fix this?

Solution

To get the hamburger icon, the following code is enough

Toolbar toolbar =(Toolbar)findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

It shows the back button because you are using a method setDisplayHomeAsUpEnabled(true);

Check out the official quote Click here

Related Problems and Solutions