Dismiss PopupWindow on touch outside popup, without using deprecated constructor

杀马特。学长 韩版系。学妹 提交于 2019-12-03 10:41:42

What I had to do to get it to work:

popup.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(context, android.R.color.transparent)));
popup.setOutsideTouchable(true);

Hmm setBackgroundDrawable don't dissmiss popup window. I think that default behavior of popup window is to dismiss on touching outside but you may add onDismiss listener like that

popup.setOnDismissListener(new PopupWindow.OnDismissListener() {

    @Override
    public void onDismiss() {
        popup.dismiss();
        // end may TODO anything else                   
    }
});

You could try.

popup.setBackgroundDrawable(new BitmapDrawable(getResources(),
            ""));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!