Siddharth Srivastava Siddharth Srivastava - 3 months ago 20
Android Question

ActionBarDrawerToggle icon missing when using AppCompat v22

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.

Answer

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..)

Comments