`
yxwang0615
  • 浏览: 550415 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

PopupWindow 点击窗口外的空间关闭[学习]

 
阅读更多

如何使用PopupWindow:

 

		//初始化popuwindow
		 LayoutInflater mLayoutInflater = (LayoutInflater) SubList.this.getSystemService(LAYOUT_INFLATER_SERVICE);  
		 View title_popunwindwow = mLayoutInflater.inflate(R.layout.sublist_popuwindow, null); 
		PopupWindow mPopupWindow = new PopupWindow(title_popunwindwow, LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT,true);
		 mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//点击窗口外消失
		 mPopupWindow.setOutsideTouchable(true); 
 

显示PopupWindow:

mPopupWindow.showAsDropDown(findViewById(R.id.titlebar_center),-43,0);

  pw.showAtLocation(view, Gravity.CENTER, -(view.getWidth()),y);

 若需要监听PopUpWindow里控件的事件,如PopUpWindow里面一个按钮的事件,那么就需要调用方法setFocusable(true)获得焦点,并且在调用setFocusable(true)方法后,可以通过Back(返回)菜单使PopUpWindow dimiss;另外调用方法setOutsideTouchable(true)后,点击PopUpWindow外面的控件也可以使得PopUpWindow dimiss。需要顺利让PopUpWindow dimiss;PopUpWindow的背景不能为空。

分享到:
评论
1 楼 jianghao3616 2012-05-07  
这位大侠,请问下我在这个popupWindow的xml里设置了背景,为啥不好使呢,然后再代码里加了你的这行mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//点击窗口外消失  就好用了。但是背景还是之前的背景。。。求指教啊

相关推荐

Global site tag (gtag.js) - Google Analytics