Not working onbackpressed when setcancelable of alertdialog is false

后端 未结 5 1137
名媛妹妹
名媛妹妹 2020-12-06 18:02

I have an AlertDialog and its setCancelable() is false. In Onbackpressed function I want the AlertDialog to be closed. But when setCancelable

5条回答
  •  不知归路
    2020-12-06 18:35

    if you don't want to close the dialog when touched outside area of the dialog, you can set the property

        permissionDialog.setCanceledOnTouchOutside(false)
    

    and if you want to dismiss the dialog on backpress you need to call the method on keyListener

     permissionDialog?.setOnKeyListener { dialog, keyCode, _ ->
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                dialog?.dismiss()
                true
            }
            false
        }
    

提交回复
热议问题