본문 바로가기
Android

PopupWindow : BackKey 나 BackGround touch로 dismiss시키기

by Leo 리오 2010. 11. 7.
반응형

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.

반응형

'Android' 카테고리의 다른 글

안드로이드 예제들  (0) 2011.05.04
List View - UI thread 에러  (5) 2011.04.21
achartengine에서 TimeBarChart 만들기  (5) 2011.01.08
구글맵 맵상에서 거리구하기  (0) 2010.11.24
failed to find provider info for settings  (0) 2010.11.17

댓글