Dismiss PopupWindow on touch outside popup, without using deprecated constructor

前端 未结 3 653
遇见更好的自我
遇见更好的自我 2021-02-13 04:55

I have a PopupWindow and I wanted it to dismiss when the user touches outside, so I looked into and found out that I had to use popup.setBackgroundDrawable(new BitmapDrawa

相关标签:
3条回答
  • 2021-02-13 05:17

    What I had to do to get it to work:

    popup.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(context, android.R.color.transparent)));
    popup.setOutsideTouchable(true);
    
    0 讨论(0)
  • 2021-02-13 05:19

    You could try.

    popup.setBackgroundDrawable(new BitmapDrawable(getResources(),
                ""));
    
    0 讨论(0)
  • 2021-02-13 05:21

    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                   
        }
    });
    
    0 讨论(0)
提交回复
热议问题