dismiss the popup window by back button

烈酒焚心 提交于 2019-11-29 06:06:10

Replace

popupWindow.setOutsideTouchable(false);

with this

popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);

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
            }
        }
    });
Jitesh Upadhyay

please write onBackPressed() and have following code

if(popup!=null){
   //dismiss the popup
   popup.dismiss();
   //make popup null again
   popup=null;
}
M D

Try this way: Implement onBackPressed() and add

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

And set your PopWindow with below:

popup.setOutsideTouchable(true);

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.

Hariharan

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();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!