android开发DialogFragment禁止按back键消失的解决方法

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val ctx = context ?: return super.onCreateDialog(savedInstanceState)
var builder: AlertDialog.Builder = AlertDialog.Builder(ctx, R.style.CenterDialogStyle)
builder.setView(view)
val dialog = builder.create()
dialog.setCanceledOnTouchOutside(false)
dialog.setCancelable(false) //无效
isCancelable = false  //有效,设置这个才有效,上面的那个无效,坑死了,网上一堆无用的监听key事件,我去。。。
return dialog
}
原文地址:https://www.cnblogs.com/yongfengnice/p/13366624.html