如何在BottomSheetDialogFragment之上显示另一个碎片(fragment)

7
有没有办法在DialogFragment的顶部显示片段?当我的BottomSheetDialogFragment在某些操作后显示时,我需要显示另一个片段(不是对话框片段),而不必关闭该对话框,我尝试从对话框中删除模糊效果,然后隐藏视图,但那不好,对话框片段是不可见的,但它仍然在顶部,按下返回键会先删除这个不可见的对话框,我需要实现的是正常的后台堆栈顺序,就像“普通”片段一样
1个回答

2

我也遇到了同样的问题,我找到的解决方案是:

  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()
    
注意:当您按下返回按钮时,它会关闭整个对话框,因此我在第二个片段中放置了一个X图标,调用parentFragmentManager.popBackStack()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接