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
}

 

posted @ 2020-07-23 15:33  yongfengnice  阅读(1890)  评论(0编辑  收藏  举报