陷入困境BottomSheetDialogFragment

时间:2020-09-06 19:49:53

标签: java android kotlin bottom-sheet

我有两个BottomSheetDialogFragment:BottomSheetDialogFragment1和BottomSheetDialogFragment2,我想从BottomSheetDialogFragment1转到BottomSheetDialogFragment2,这是类似于此代码的示例

    val bottomSheetDialogFragment2 = BottomSheetDialogFragment2()
        bottomSheetDialogFragment2.show(childFragmentManager, bottomSheetDialogFragment1.tag)

但是当我像这样的代码重定向到BottomSheetDialogFragment2之后将解散bottomSheetDialogFragment2

        val bottomSheetDialogFragment2 = BottomSheetDialogFragment2()
        bottomSheetDialogFragment2.show(childFragmentManager, bottomSheetDialogFragment1.tag)

dismiss()

结果:BottomSheetDialogFragment1和BottomSheetDialogFragment2是dismiss(),我希望Juste能够解散一个BottomSheet。

1 个答案:

答案 0 :(得分:0)

尝试使用活动中的“片段”管理器:

  val bottomSheetDialogFragment2 = BottomSheetDialogFragment2()
  bottomSheetDialogFragment2.show(parentFragmentManager, bottomSheetDialogFragment1.tag)

还可以使用showNow方法来防止在对话框之间切换时在屏幕上闪烁:

  val bottomSheetDialogFragment2 = BottomSheetDialogFragment2()
  bottomSheetDialogFragment2.showNow(parentFragmentManager,bottomSheetDialogFragment1.tag)

请注意,如果您在将此方法附加到活动之前调用此方法,则parentFragmentManager方法可能会引发异常,这是文档:

https://developer.android.com/reference/androidx/fragment/app/Fragment#getParentFragmentManager()