Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setDisplayHomeAsUpEnabled() + Up Arrow?

Tags:

android

We can use the setDisplayHomeAsUpEnabled() method on an activity to display the "up" arrow on the action bar.

If I understand correctly, we're only really supposed to show the up arrow if we're not the root activity.

Clicking the "up" arrow should take us to the root activity. Is that all there is to it? I should then add this call to all my activities like so:

class RootActivity {
    public void onCreate() {
        setDisplayHomeAsUpEnabled(false);
    }
}

class AppleActivity {
    public void onCreate() {
        setDisplayHomeAsUpEnabled(true);
    }
}

class OrangeActivity {
    public void onCreate() {
        setDisplayHomeAsUpEnabled(true);
    }
}

...
like image 395
user291701 Avatar asked Jan 23 '12 21:01

user291701


1 Answers

Yes, that's pretty much it.

Clicking the up-arrow should take you towards the root.

and don't forget to actually handle the click in onOptionsItemSelected by checking the item id against android.R.id.home

like image 179
lordl Avatar answered Oct 11 '22 00:10

lordl