0

I have a PopupWindow and it is setFocusable(false), I want to dismiss it when touch outside, and it is already setOutsideTouchable(true), but with the setFocusable(false) it doesn't work, how can I solve this? Thanks in advance.

All the properties being set to my PopupWindow are as follows:

popUpWindow.setBackgroundDrawable(xx);
popUpWindow.setTouchable(true);
popUpWindow.setFocusable(false);
popUpWindow.setOutsideTouchable(true);
popUpWindow.setAnimationStyle(android.R.style.Animation_Dialog);
popUpWindow.update();

update:

I was wrong, the PopupWindow dismissed, but some other code make it show.

twlkyao
  • 14,302
  • 7
  • 27
  • 44

1 Answers1

3

it may work

// Removes default background.
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
myPopupWindow.setOutsideTouchable(true);

Alternatively:

myPopupWindow.setFocusable(true);

Not sure what the differences are, but the ListPopupWindow source code actually uses the latter when it's modality is set to true with setModal, so at least the Android developers consider this a viable approach, and it's only one line.

BTW, Don't use BitmapDrawable deprecated constructor, use this new ColorDrawable(android.R.color.transparent) to replace default background.

Happy Coding :)

Shrenik Shah
  • 1,900
  • 1
  • 11
  • 19
  • @twlkyao can you post your popup window initialisation including all property you are setting up ? and what's your actual purpose to make it focusable false ? – Shrenik Shah Mar 07 '17 at 10:19
  • I was wrong, it dismissed, but somewhere make it show. – twlkyao Mar 07 '17 at 10:30