user2770916 user2770916 - 2 months ago 11x
Java Question

ActionBarDrawerToggle() icon cannot be set to the ActionBar in Android SDK 5

I have a simple problem with initializing my icon for my action bar.
I am using Android SDK 5 and since;
was deprecated I imported v7 support and replaced my import with the following:;

i.e. the same package with v7.

Now when I initialize my ActionBarDrawerToggle object to associate with my
object imported from:
I am forced to remove one argument, which seems ok (have no idea why though!).
but my icon does not go in my ActionBar.
here is the my initialization for my ActionBarDrawerToggle object:

mActionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.ic_drawer, R.string.drawer_open) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()


/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View view) {
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()


I have the image in my resource namely

I cant seem to find why my icon does not appear in v7.

P.S. the code works perfectly fine, infact when I switch back to v4 import and add the extra argument for toggle object initialization (having to bare with the ugly deprecated cross line ofcourse), the icon appears but not in v7.

thanks in advance :)


Actually if you look at javadoc of new v7.ActionBarDrawerToggle you could realize that new class doesn't provide the constructor, that takes Drawable as an argument - the 3rd argument where you've provided your Drawable is a String resourse that describes opening drawer. If you want to set a custom icon you have to use another ActionBarDrawerToggle constructor:

ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes)

In that case toolbar's navigation icon will be used as a Drawer icon