Jemo Mgebrishvili
Jemo Mgebrishvili

Reputation: 5487

How to display another fragment on top of BottomSheetDialogFragment

Is there any way to display fragment on top of DialogFragment? When my BottomSheetDialogFragment is shown after some action I need to display another fragment (not type of dialog fragment) without dismiss of the that dialog, I tried to remove dim effect from dialog and than hide the view, but that is not good, dialog fragment is invisible but, it is steel on top and back press removes this invisible dialog first, what I need to achieve is normal back stack order, like "normal" fragments

Upvotes: 8

Views: 2651

Answers (1)

axiel7
axiel7

Reputation: 71

I was having the same problem and the solution I found is:

  1. In the BottomSheetDialogFragment layout, set an id to a ViewGroup (you can use the root view or add a FrameLayout somewhere)

  2. In the BottomSheetDialogFragment class use this to open the new fragment:

     childFragmentManager.beginTransaction()
             .add(R.id.yourId, newFragment, newFragment.tag)
             .addToBackStack(newFragment.tag)
             .commit()
    

Caveat: when you press the back button it closes the entire dialog, so I put an X icon in the second fragment that calls parentFragmentManager.popBackStack()

Upvotes: 2

Related Questions