Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Default HomeAsUp on Custom ActionBar

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?

like image 822
Adifyr Avatar asked Mar 22 '23 23:03

Adifyr


1 Answers

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.

like image 57
user3072116 Avatar answered Apr 26 '23 07:04

user3072116