PopupWindow를 제거를 하려고하면 밖에를 터치해도 backkey를 눌러도 반응이없다.

KeyEvent로 받으려고 해도 받아지지가 않는다.




  popupview = View.inflate(this, R.layout.dialog_popup, null);
  popup = new PopupWindow(popupview,200,100,true);
  popup.setOutsideTouchable(true);
  popup.setBackgroundDrawable(new BitmapDrawable()) ;



This is because the popup window does not respond to onTouchr onKey events unless it t has a background that != null. Check out some code I wrote co help with this. In the basic case you tan to call PopupWindow#setBackgroundDrawable(new BitmapDrawable()) oo force it to act the way you expect. You won't need your own onKey listener. You might also need to call PopupWindow#setOutsideTouchable(true) if you want it to go away when the user clicks outside of the window boundaries.
[이건 popupwindow가 (background가 null이면) 밖의 터치에 반응하지 않기 때문이다. 위코드를 보면 PopupWindow#setBackgroundDrawable(new BitmapDrawable()) 가 당신이 원한 기능을 만들어준다. onkey listener를 등록할 필욘없다. PopupWindow#setOutsideTouchable(true)만등록하면 창의 밖을 터치하면 창이 없어지게된다.]


Extended esoteric answer:
The reason the background cannot be null is because of what happens in PopupWindow#preparePopup. If it detects background != null it creates an instance of PopupViewContainer and calls setBackgroundDrawable on that and puts your content view in it. PopupViewContainer is basically a FrameLayout that listens for touch events and the KeyEvent.KEYCODE_BACK event to dismiss the window. If background == null, it doesn't do any of that and just uses your content view. You can, as an alternative to depending on PopupWindow to handle that, extend your root ViewGroup to behave the way you want.

신고
Posted by Leo 리오 트랙백 0 : 댓글 7

티스토리 툴바