How to Prevent an Alert Dialog Getting Closed by Back Button

后端 未结 3 2065
一个人的身影
一个人的身影 2021-02-12 19:19

I have an alert dialog like this:

    AlertDialog.Builder oyunaBaslaDialog = new AlertDialog.Builder(this);
    oyunaBaslaDialog.setMessage(\"A Takımı\");
    oy         


        
相关标签:
3条回答
  • 2021-02-12 20:04

    Implement setOnKeyListener and catch the KeyEvent.KEYCODE_BACK. If you return true in this method, dialog will not close.

    0 讨论(0)
  • 2021-02-12 20:10

    there is a method called, bulder.setCancelable().by default this cancelable set 'true'.override it with,

    bulder.setCancelable(false)
    
    0 讨论(0)
  • 2021-02-12 20:14

    Use Dialog.setCancelable():

    Sets whether this dialog is cancelable with the BACK key.

    In your code this would be:

    oyunaBaslaDialog.setCancelable(false);
    
    0 讨论(0)
提交回复
热议问题