【问题标题】:How to disable BottomSheetDialogFragment getting dismissed on outside touch [duplicate]如何禁用BottomSheetDialogFragment在外部触摸时被解雇[重复]
【发布时间】:2019-06-14 06:07:21
【问题描述】:

点击按钮时,屏幕显示BottomSheetDialogFragment,但当我触摸窗口外部时,它会被关闭。

有没有办法像我们使用 api setCanceledOnTouchOutside 进行对话一样禁用它。我曾尝试在我的班级的onCreateDialog 方法(扩展BottomSheetDialogFragment)中使用设置setCanceledOnTouchOutside = false,但没有运气。

【问题讨论】:

标签: android android-layout


【解决方案1】:

我建议在setCancelable 中设置 false,它会为你工作

BottomSheetDialogFragment btmSheetDialog = new BottomSheetDialogFragment();
btmSheetDialog.setCancelable(false);
btmSheetDialog.show(getChildFragmentManager(), btmSheetDialog.getTag());

【讨论】:

    【解决方案2】:

    你必须像下面那样做

    val bottomSheetDialogFragment = BottomSheetDialogFragment()
            bottomSheetDialogFragment.isCancelable = false
            bottomSheetDialogFragment.show(supportFragmentManager, bottomSheetDialogFragment.tag)
    

    【讨论】:

      【解决方案3】:

      基于DialogFragment文档

      https://developer.android.com/reference/android/support/v4/app/DialogFragment.html#setCancelable(boolean)

      控制显示的对话框是否可取消。使用 this 而不是直接调用Dialog.setCancelable(boolean),因为 DialogFragment 需要基于 this 改变其行为。

      Params:
      cancelable – If true, the dialog is cancelable. The default is true.
      

      你可以试试这个:

      在 Kotlin 中

         val switchAccountBottomSheet = SwitchAccountBottomSheet()
         switchAccountBottomSheet.isCancelable = false
         switchAccountBottomSheet.show(getActivity().getSupportFragmentManager(), SwitchAccountBottomSheet.class.getName());
      

      在 Java 中

      SwitchAccountBottomSheet mSwitchAccountBottomSheet = new SwitchAccountBottomSheet();
      mSwitchAccountBottomSheet.setCancelable(false);
      mSwitchAccountBottomSheet.show(getActivity().getSupportFragmentManager(), SwitchAccountBottomSheet.class.getName());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-28
        • 1970-01-01
        • 1970-01-01
        • 2016-07-15
        • 1970-01-01
        • 2017-07-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多