BottomSheetDialog setCanceledOnTouch 在 Kotlin 之外

BottomSheetDialog setCanceledOnTouchOutside Kotlin

我创建了一个底部 sheet 对话框并正在实现取消功能。

触摸对话框外部时不能关闭它,但底部导航应该能捕捉到触摸。经过长时间的试用,我意识到我不能在 Kotlin 上使用“setCanceledOnTouchOutside”。 “isCancelable=false”有效但无法在底部导航中使用后退按钮。想让底部导航只可触摸怎么办?

任何帮助将不胜感激

My code is here

class BiometricChangeDetectDialog: BottomSheetDialogFragment() {
private var _binding: DialogBiometricChangeDetectBinding? = null
private val binding get() = _binding!!
private lateinit var mContext: MainActivity

override fun onAttach(context: Context) {
    super.onAttach(context)
    mContext = context as MainActivity
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    
    AlertDialog.Builder(requireContext()).apply {
        isCancelable = false
        //change here to setCanceledOnTouchOutside
    }

}

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
    _binding = DialogBiometricChangeDetectBinding.inflate(inflater, container, false)
    val view = binding.root

    binding.btnEmail.setOnClickListener {
        dismiss()
        findNavController().navigate(R.id.action_biometricChangeDetectDialog_to_biometricChangeEmailDialog)
    }

    binding.btnSms.setOnClickListener {
        dismiss()
        findNavController().navigate(R.id.action_biometricChangeDetectDialog_to_biometricChangeEmailDialog)
    }
    return view
}

override fun onDestroyView() {
    super.onDestroyView()
    _binding = null
}

}

onCreateView

中添加这一行

dialog?.setCanceledOnTouchOutside(false)