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);
}
}
...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With