4

I have a custom android action bar with a custom layout view and style. I need to show the 'Home As Up' Button for my navigation drawer. The problem is that the button is not showing up in my custom layout style. I need the android default home as up icon so that I may have a default navigation drawer icon. (The icon which has the animation of the navigation drawer opening and closing).

Now I tried doing

getActionBar().setDisplayHomeUpAsEnabled(true);

getActionBar().setHomeButtonEnabled(true)

But the home button does not show up. Can anyone tell my how to implement the default home button on the custom actionbar?

Adifyr
  • 2,649
  • 7
  • 41
  • 62

2 Answers2

7

For me this works to display the up navigation. I'm still figuring out how to actually implement the up navigation.

getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);

It appears you can just use the convenience function to handle up like this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent intent;
            intent = NavUtils.getParentActivityIntent(this);
            NavUtils.navigateUpTo(this, intent);
            return true;
    }
    return super.onOptionsItemSelected(item);
}

To handle buttons in the custom part you can add onClick in the layouts and implement the specified functions.

0

Old Question, but here's what I used on mine...

...
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
getActionBar().setDisplayHomeAsUpEnabled(true);
...

And then in the AndroidManifest.xml:

<activity
    ...
    android:parentActivityName="com.example.app.MainActivity"
  <meta-data
      android:name="android.support.PARENT_ACTIVITY"
      android:value="com.example.app.MainActivity">
  </meta-data>
</activity>

The meta-data values are for Android 4.0 and below support if using ActionBarSherlock or AppCompat, but for 4.1 and above just add the android:parentActivityName to the activity declaration in the manifest.

This allowed me to use the up navigation (show the button AND actually navigate up) while I had a custom Action Bar layout.

Hope this helps you or someone else in the future.

death2all110
  • 222
  • 3
  • 14