我有两个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都使用了BottomSheet (),而我只喜欢忽略一个and。
发布于 2020-09-07 07:46:45
尝试使用activity中的片段管理器:
val bottomSheetDialogFragment2 = BottomSheetDialogFragment2()
bottomSheetDialogFragment2.show(parentFragmentManager, bottomSheetDialogFragment1.tag)此外,您还可以使用showNow方法来防止在对话框之间转换时屏幕上的闪烁:
val bottomSheetDialogFragment2 = BottomSheetDialogFragment2()
bottomSheetDialogFragment2.showNow(parentFragmentManager,bottomSheetDialogFragment1.tag)请注意,如果您在将此方法附加到activity之前调用此方法,则parentFragmentManager方法可能会抛出异常,以下是文档:
https://developer.android.com/reference/androidx/fragment/app/Fragment#getParentFragmentManager()
https://stackoverflow.com/questions/63768292
复制相似问题