Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Android Studio Navigation Drawer Activity Template does not show Hamburger Icon, only arrow icon

This person is basically running into the same problem I'm having, however, the provided solution is not helpful, nor does it work for me since my code is in fact calling mDrawerToggle.sycnState() (in a deferred Runnable).

I've also tried adding it to onActivityCreated in my Fragment, which doesn't seem to do anything. Not knowing exactly what syncState does, I can't tell if it's syncing the state of being open (which the template code makes happen by default), and then it never is synced again when the drawer is manually closed.

I'd post code but you can test this by making a new project in Android Studio (1.2.2), selecting the Navigation Drawer Activity, and then simply running the project - no changes necessary. You'll see that the only icon is ever the <- arrow. I've even set breakpoints to inspect the ActionBarDrawerToggle object which in fact has the hamburger icon in its memory for the icon to draw, flummoxing me even more!

I'm at my wits end here.

like image 285
Enuratique Avatar asked Jun 12 '15 16:06

Enuratique


People also ask

How do I show navigation drawer in all activities?

The user can view the navigation drawer when they swipe the activity's screen from the left edge of the android device. A user can also find it from the activity, by tapping the app icon (also known as the “hamburger” menu) in the action bar.

What is drawer layout in Android?

DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.


1 Answers

I just figured out a solution in case anyone else is having this problem:

Change the import at the top of the fragment from

import android.support.v4.app.ActionBarDrawerToggle;

to

import android.support.v7.app.ActionBarDrawerToggle;

then change the code in setUp from

mDrawerToggle = new ActionBarDrawerToggle(
            getActivity(),                    /* host Activity */
            mDrawerLayout,                    /* DrawerLayout object */
            R.drawable.ic_drawer,             /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
    )

to

mDrawerToggle = new ActionBarDrawerToggle(
            getActivity(),                    /* host Activity */
            mDrawerLayout,                    /* DrawerLayout object */
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
    )
like image 179
Enuratique Avatar answered Sep 24 '22 23:09

Enuratique