dismiss the popup window by back button

前端 未结 6 1269
感情败类
感情败类 2020-12-17 17:38

I want to Dismiss the popup window by clicking outside of the popup window or by the back button, but when click on the back button my application exit\'s, instead of exitin

相关标签:
6条回答
  • 2020-12-17 18:18

    You can override onBackPressed() callback in your code and check to see if your pop-up is already showing(then dismiss it), else you call super to get normal behavior.

    0 讨论(0)
  • 2020-12-17 18:26

    Try this way: Implement onBackPressed() and add

    if(popup!=null) {
        popup.dismiss();
        popup=null;
    }
    

    And set your PopWindow with below:

    popup.setOutsideTouchable(true);
    
    0 讨论(0)
  • 2020-12-17 18:28

    Maintain global reference for PopUpWindow and override onBackPressed()...

    @Override
    public void onBackPressed() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
        } else {
            super.onBackPressed();
        }
    }
    

    To dismiss by the same Button...

        ivmainmenu.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                if(popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                    popupWindow = null;
                } else {
                    // show pop up now
                }
            }
        });
    
    0 讨论(0)
  • 2020-12-17 18:35

    Try this..

    Use PopupWindow popupWindow as Global variable

    use popup.setOutsideTouchable(true);

    @Override
    public void onBackPressed() {
        if (popupWindow != null) {
            if (popupWindow.isShowing()) {
                popupWindow.dismiss();
            }
        } else {
            finish();
        }
    }
    
    0 讨论(0)
  • 2020-12-17 18:36

    Replace

    popupWindow.setOutsideTouchable(false);
    

    with this

    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    
    0 讨论(0)
  • 2020-12-17 18:37

    please write onBackPressed() and have following code

    if(popup!=null){
       //dismiss the popup
       popup.dismiss();
       //make popup null again
       popup=null;
    }
    
    0 讨论(0)
提交回复
热议问题