How to handle Back button with in the dialog?

后端 未结 8 2280
无人共我
无人共我 2020-11-30 01:02

I am developing an application that when the button is pressed, it opens a dialog with OK and Cancel buttons.

It works fine.

When the user presses the back b

8条回答
  •  無奈伤痛
    2020-11-30 01:34

    Try this

     new AlertDialog.Builder(this).setOnKeyListener(new DialogInterface.OnKeyListener() {
    
                            @Override
                            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    
                                if(keyCode == KeyEvent.KEYCODE_BACK){
                                    Logger.d(TAG, "--------- Do Something -----------");
                                    return true;
                                }
                                return false;
    
    
                            }
                        })
    

提交回复
热议问题