我創建了一個底部表單對話框并正在實作取消功能。
當觸摸對話框外部時,它必須不被關閉,但底部導航應該抓住觸摸。經過長時間的試用,我意識到我不能在 Kotlin 上使用“setCanceledOnTouchOutside”。“isCancelable=false”正在作業,但不能在底部導航上使用后退按鈕。如果我想讓底部導航只能觸摸怎么辦?
任何幫助將不勝感激
我的代碼在這里
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
}
}
uj5u.com熱心網友回復:
加入這一行 onCreateView
dialog?.setCanceledOnTouchOutside(false)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/396675.html
標籤:安卓 科特林 对话 触碰 android-alertdialog
上一篇:Flutter-卡片高程無陰影
