Using FragmentTransaction with a DialogFragment

前端 未结 4 1907
后悔当初
后悔当初 2021-02-05 18:03

So I\'ve created a DialogFragment that is shown as a dialog via this technique

Now that it\'s launched and upon a user interaction within this popup I want to slide in a

4条回答
  •  被撕碎了的回忆
    2021-02-05 18:58

    Display a DialogFragment with commitAllowingStateLoss()

    The DialogFragment.show(FragmentManager manager, String tag) doesn’t have an option to show the dialog while allowing state-loss. It’s a bit strange and inconsistent, because there is a DialogFragment.dismissAllowingStateLoss().

    But you can always commit the DialogFragment transaction manually, or create a helper method like this:

    public static void showDialogAllowingStateLoss(FragmentManager fragmentManager, DialogFragment dialogFragment, String tag) {
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.add(dialogFragment, tag);
    ft.commitAllowingStateLoss();
    }
    

提交回复
热议问题