简体   繁体   English

向上动作按钮未显示在工具栏上

[英]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 我正在片段时(使用1个父级活动)尝试在工具栏上显示操作按钮,如下所示: https : //developer.android.com/training/implementing-navigation/ancestral.html

This up button must work as standard BackPress. 此向上按钮必须作为标准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 ) 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. 如果您的片段已添加到BackStack中,然后按回去,它将作为标准导航弹出。

If user presses the UP button then handle the Menu Home button and check is there any Fragment in Backstack then pop it. 如果用户按下UP按钮,则处理Menu Home按钮,然后检查Backstack中是否有任何片段,然后将其弹出。

popBackStack(int arg0, int arg1);

popBackStack(String arg0, int arg1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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