customAnimation when calling popBackStack on a FragmentManager

后端 未结 1 905
遇见更好的自我
遇见更好的自我 2021-02-02 07:50

In my activity, with the touch of a button, I replace the current fragment with a new fragment using a custom animation, like in this example.

@Override
public b         


        
1条回答
  •  囚心锁ツ
    2021-02-02 08:15

    After further reading of the documentation, I found that using this signature of setCustomAnimation allowed the animation to be played when pressing the back button or calling getFragmentManager().popBackStack();

    I modified my code like this

    ...
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in, android.R.animator.fade_out);
    anomalieFragment = new AnomalieListFragment();
    ft.replace(R.id.content, anomalieFragment);
    ft.addToBackStack(null);
    ft.commit();
    ...
    

    0 讨论(0)
提交回复
热议问题