在从一个片段导航到属于同一活动的另一个片段时,我正在使用幻灯片动画。
WebFragment fragment = WebFragment.newInstance(Globals.TGURL_CREATE_ACTIVITY, "");
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.enter_anim, R.anim.exit_anim);
transaction.replace(R.id.fragment_activity_layout, fragment);
transaction.addToBackStack(null);
transaction.commit();
这段代码确保当我回到第一个片段时,动画就在那里。
到目前为止,这对我来说是一个福音。但在一个特定情况下,它正在成为一种诅咒。活动放置在ActionBar
选项卡上。当第二个(WebFragment)是当前片段时,我点击选项卡而不是后退按钮,我希望第一个片段在没有任何动画的情况下显示。
但就导航继承之前给出的动画而言,我不可能做到这一点。
这就是我要回去做的事情:
TabActivity.this.getSupportFragmentManager().popBackStack();