user1634451
user1634451

Reputation: 5212

Navigation Drawer icon not showing (Sherlock actionbar)

Have the navigation Drawer working with the sherlock actionbar but i am having trouble getting the 3 line icon (like gmail) to show instead of the normal up button "<". Here is my code ic_drawer is the 3 line icon that gmail uses

getSupportActionBar().setIcon(R.drawable.myIcon);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer,
            R.drawable.ic_drawer, R.string.menu_open, R.string.menu_close) {
        public void onDrawerClosed(View view) {

            super.onDrawerClosed(view);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

Upvotes: 19

Views: 14278

Answers (11)

KiranKiki
KiranKiki

Reputation: 91

I have added this line before calling setDrawerListener.

mDrawerLayout.post(new Runnable() {
@Override public void run() {
 mDrawerToggle.syncState();
}
});

Hope this will fix the issue in lower devices.

Upvotes: 0

Bruce
Bruce

Reputation: 127

@zudo1337 's method solved my problem.

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

Upvotes: 0

zudo1337
zudo1337

Reputation: 21

I put this in and it works.

    @Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

Upvotes: 0

Dory
Dory

Reputation: 7582

This solution worked for me, and showed default navigation drawer icon in all version. Add SherlockNavigationDrawer library from here https://github.com/nicolasjafelle/SherlockNavigationDrawer to your project. And change your code as below :

SherlockActionBarDrawerToggle mDrawerToggle = new SherlockActionBarDrawerToggle(this,mDrawerLayout,
   R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
   public void onDrawerClosed(View view) {
       super.onDrawerClosed(view);
   }
   public void onDrawerOpened(View drawerView) {
       super.onDrawerOpened(drawerView);
   }
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);

Upvotes: 21

Raveesh Bhalla
Raveesh Bhalla

Reputation: 921

Though I'm guessing by now you must have worked it out, just wanted to submit an answer:

Change your code to the following:

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer,
        R.drawable.ic_drawer, R.string.menu_open, R.string.menu_close) {
    public void onDrawerClosed(View view) {

        super.onDrawerClosed(view);
    }

    public void onDrawerOpened(View drawerView) {
        super.onDrawerOpened(drawerView);
    }
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setIcon(R.drawable.myIcon);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);

Essentially, the ActionBar options that you are setting in code need to be set after the DrawerToggle has been completed, not before.

Upvotes: 3

Daniel De Le&#243;n
Daniel De Le&#243;n

Reputation: 13639

This happen when you run your app in Android < 3, even Google apps suffer of this too.

But there is a project than solve this: https://github.com/nicolasjafelle/SherlockNavigationDrawer

Upvotes: 0

wazim
wazim

Reputation: 401

Have you tried implementing the method:

    mDrawerToggle.syncState();

This has worked for me in the past.

Upvotes: 40

user1361425
user1361425

Reputation: 87

May be this will work...

in onCreateOptionMenu inflate your menu layout getSupportMenuInflater().inflate(R.menu.action_bar_menu, menu);

Upvotes: -2

Ansh
Ansh

Reputation: 2396

What you can do is create a style like below:

 <style name="AppTheme" parent="Your Theme name">
        <item name="homeAsUpIndicator">@drawable/ic_drawer</item>
 </style>

And in Android manifest apply this theme like:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
</application>

This will solve the issue getting the 3 line icon for sure.

Upvotes: 3

Topper Harley
Topper Harley

Reputation: 12374

Did you add the toggle to your drawer?

mDrawerLayout.setDrawerListener(mDrawerToggle);

Upvotes: 1

Borys
Borys

Reputation: 1813

You can look at this post first. There is one answer: "You can change back icon in Theme

<item name="android:homeAsUpIndicator">@drawable/action_arrow</item>

But I think you want implement Navigation Drawer, so read about it.

Upvotes: 2

Related Questions