我有两个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。
答案 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()