`
寻梦者
  • 浏览: 626066 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

android中popupwindow使用技巧

 
阅读更多

在项目中遇到,点击popupwindow背景activity界面,使得popupwindow消失。

网上查阅了相关资料,最后实现:

 

 

window.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_tcbox));
window.setOutsideTouchable(true);

    这两段代码很重要

 

 

   popupWindow = getPopWindow();

			popupWindow.showAtLocation(findViewById(R.id.ll_root), Gravity.BOTTOM, 0, 0);
		

protected PopupWindow getPopWindow() {
		View popupWindow_view = getLayoutInflater().inflate( // 获取自定义布局文件dialog.xml的视图
				R.layout.dg_weibo_detail_more, null, false);
		PopupWindow window = new PopupWindow(popupWindow_view, ResolutionUtil.getWPx(),
				ResolutionUtil.getHPx() / 3, true);// 创建PopupWindow实例
		window.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_tcbox));
		window.setOutsideTouchable(true);
		return window;
}


@Override
public boolean onTouchEvent(MotionEvent event) {
		if (popupWindow != null && popupWindow.isShowing()) {
			popupWindow.dismiss();
			popupWindow = null;
		}
		return super.onTouchEvent(event);
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics