问题描述:

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.

网友答案:

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

网友答案:

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.

网友答案:

also be sure to use the right theme on your actionbar...if your actionbar is dark, the default icon might be black unless you do this: "@style/ThemeOverlay.AppCompat.Dark.ActionBar"

It bit me, but only on Android 4.x devices (5.x+ worked fine oddly enough)

相关阅读:
Top