Search code examples
androidactionbarsherlocknavigation-drawer

Up icon not showing in lower levels when Nav. Drawer is configured


OK, that was a clumsy title :(

Here's the description of the problem. There are two Activities: MainActivity & PreferenceActivity.

The MainActivity has drawer set up (per tutorial) and working fine (behavior, three-line icon, everything).

The problem is that the PreferenceActivity also shows the R.drawable.ic_drawer, this is not as intended.

Intended behavior is to have < icon in the PreferenceActivity action bar.

The only changes to PreferenceActivity are:

  • onCreate() I have added getSupportActionBar().setDisplayHomeAsUpEnabled(true); and
  • I have overriden onOptionsItemSelected() (to handle android.R.id.home click to track some analytics).

I have tried suggestions from this question. Based on that, I have added setDrawerIndicatorEnabled(true); in the MainActivity.onResume() and have added setDrawerIndicatorEnabled(false); in MainActivity.onPause(), but w/o any effect.

Ideas hove to solve this?

Could it be that the setDrawerIndicatorEnabled(false) doesn't correctly revert the indicator because ActionBarSherlock defines the attribute for it (in its theme) as "homeAsUpIndicator" and not as "android.R.attr.homeAsUpIndicator" (as described here)?


Solution

  • The latest edit of the question (regarding ABS) got me thinking.

    Since I had problems with drower icon not moving, I have added this to my theme (extending ABS theme):

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

    Since actually this fixed the mentioned problem (of drawer icon not moving):

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

    the attrib override in the theme was a leftover and was a root cause for < icon not showing on lower levels as it should, so removing the "android:homeAsUpIndicator" override fixed my problem.