Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarDrawerToggle icon missing when using AppCompat v22

Tags:

I'm using Appcompat v22 to use tinted style for AutoCompleteTextView. However, as soon as I changed my build.gradle from this:

compile 'com.android.support:support-v4:21.0.3' compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:cardview-v7:21.0.2' compile 'com.android.support:recyclerview-v7:21.0.2' 

to this:

compile 'com.android.support:support-v4:22.0.0' compile 'com.android.support:appcompat-v7:22.0.0' compile 'com.android.support:gridlayout-v7:22.0.0' compile 'com.android.support:cardview-v7:22.0.0' 

The ActionBarDrawerToggle Icon (Hamburger icon) goes missing. (However, if I slide from left, the drawer gets revealed)

Inside onCreate():

    mDrawerLayout = (BBDrawerLayout) findViewById(R.id.drawer_layout);     mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);     mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,             R.string.drawer_open, R.string.drawer_close) {         @Override         public void onDrawerClosed(View drawerView) {             super.onDrawerClosed(drawerView);             toolbar.setTitle(mTitle);             invalidateOptionsMenu();         }          @Override         public void onDrawerOpened(View drawerView) {             super.onDrawerOpened(drawerView);             trackEvent(TrackingAware.MENU_SHOWN, null);             toolbar.setTitle(mDrawerTitle);             invalidateOptionsMenu();         }     };      mDrawerLayout.setDrawerListener(mDrawerToggle); 

Have also called syncState()

@Override protected void onPostCreate(Bundle savedInstanceState) {     super.onPostCreate(savedInstanceState);     if (mDrawerToggle != null) {         mDrawerToggle.syncState();     } }  @Override public void onConfigurationChanged(Configuration newConfig) {     super.onConfigurationChanged(newConfig);     if (mDrawerToggle != null) {         mDrawerToggle.onConfigurationChanged(newConfig);     } } 

If I downgrade the appcompat version back to 21.0.3, everything starts to work.

like image 640
Siddharth Srivastava Avatar asked Mar 16 '15 11:03

Siddharth Srivastava


2 Answers

The relevant part is in the last line of code, I have them in my Activity.onCreate(..) method:

    _drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, 0, 0);     drawerLayout.setDrawerListener(_drawerToggle);     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

As I remember that line is documented too but in appcompat v21 they were ignored (or at least the default was different..)

like image 99
Gianluca P. Avatar answered Nov 18 '22 16:11

Gianluca P.


For those encountering the same problem as Dapp (toggle showing back arrow instead of hamburger icon), this is most likely because you're missing a drawerToggle.syncState() in your Activity.

To be more specific, you have to override the onPostCreate() method like this :

@Override protected void onPostCreate(Bundle savedInstanceState) {     super.onPostCreate(savedInstanceState);     drawerToggle.syncState(); } 

This isn't the only method that needs to be overriden. See this post by jpardogo for more details.

like image 24
Ronan Avatar answered Nov 18 '22 16:11

Ronan