setOnCancelListener and setOnDismissListener is not called for AlertDialog for back button pressed or touch outside

前端 未结 5 1665
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 21:48

When

  • Touch outside the dialog region
  • Press on back button

I\'m expecting onDismiss (Or onCancel) will be call

5条回答
  •  天命终不由人
    2020-12-02 22:40

    If you are using AlertDialog, see

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            // dialog dismiss without button press
        }
    });
    

    and dialog.setCanceledOnTouchOutside(true) (thanks @LeosLiterak)

提交回复
热议问题