简体   繁体   中英

Up Action Button not showing at toolbar

I'm trying to show up action button at Toolbar while I'm at fragment (using 1 parent activity) like this: https://developer.android.com/training/implementing-navigation/ancestral.html

This up button must work as standard BackPress. But the main trouble that I've got only one activity with fragment manager and I cannot specify parent activity to it. ( http://developer.android.com/training/implementing-navigation/ancestral.html#SpecifyParent )

In other, I using standard workflow:

  getMainActivity().getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_HOME_AS_UP);

  ActionBar ab = getMainActivity().getSupportActionBar();
  ab.setDisplayHomeAsUpEnabled(true);

but no result, only back arrow

To use Up button as standard Back button since there is only Activity in your Fragment. IF your Fragment has been added in BackStack then on back press it will get pop as standard nagivation.

If user presses the UP button then handle the Menu Home button and check is there any Fragment in Backstack then pop it.

popBackStack(int arg0, int arg1);

popBackStack(String arg0, int arg1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM