PopupWindow 点击后如何消失
2012-09-27 17:25
330 查看
This is because the popup window does not respond to onTouch or onKey events unless it has a background that != null. Checkout some code I wrote to help with this. In the basic case you can to call
PopupWindow#setBackgroundDrawable(new BitmapDrawable())to 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)ifyou want it to go away when the user clicks outside of the window boundaries.Extended esoteric answer:The reason the background cannot be null is because of what happens in
PopupWindow#preparePopup.If it detects
background != nullit creates an instance of
PopupViewContainerandcalls
setBackgroundDrawableonthat and puts your content view in it.
PopupViewContainerisbasically a
FrameLayoutthatlistens for touch events and the
KeyEvent.KEYCODE_BACKeventto 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
PopupWindowtohandle that, extend your root
ViewGrouptobehave the way you want.
PopupWindow pw; LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.weight_popup, (ViewGroup)findViewById(R.id.linlay_weight_popup)); pw = new PopupWindow(layout,LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT, true); pw.setBackgroundDrawable(new BitmapDrawable()); pw.setOutsideTouchable(true); pw.showAsDropDown(btnSelectWeight);
from: http://stackoverflow.com/questions/3121232/android-popup-window-dismissal
相关文章推荐
- popupwindow点击空白处如何自动消失?
- PopupWindow如何在外部点击消失和返回键
- popupwindow点击空白处如何自动消失?
- Android开发————如何点击屏幕外侧让PopUpWindow消失
- Android popupwindow 失去焦点或者点击空白区域时消失的解决方法
- PopupWindow点击窗口外的地方不消失的问题
- 如何制作点击输入框时默认文字消失的效果
- 如何让AlertDialog 在点击确定或者取消时不消失
- android:点击popupwindow以外区域 popupwindow自动消失
- 如何使Dialog可以通过点击其他区域消失
- PopupWindow点击外部和返回键消失遇到的坑
- 点击PopupWindow之外的区域让其消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 关于点击popupwindow以外区域 popupwindow自动消失问题
- 如何让AlertDialog 在点击确定或者取消时不消失
- 解决PopupWindow实现按钮点击消失和显示,以及点击它外围可以消失的方法
- 如何使Dialog可以通过点击其他区域消失。
- 点击PopupWindow 外部区域消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 点击空白处使PopUpWindow消失