首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android中popupwindow应用技巧

2012-07-24 
android中popupwindow使用技巧在项目中遇到,点击popupwindow背景activity界面,使得popupwindow消失。网上查

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;}@Overridepublic boolean onTouchEvent(MotionEvent event) {if (popupWindow != null && popupWindow.isShowing()) {popupWindow.dismiss();popupWindow = null;}return super.onTouchEvent(event);}

热点排行