实现弹出窗口后Activity背景变暗

 1     /**   
 2         * 创建PopupWindow   
 3         */     
 4         protected void initPopuptWindow() {     
 5          WindowManager windowManager = getActivity().getWindowManager();  
 6          Display display =  windowManager.getDefaultDisplay();  
 7          popupWindow = new PopupWindow(popupWindow_view, display.getWidth(),display.getHeight(), true);    
 8           // 设置动画效果     
 9          popupWindow.setAnimationStyle(R.style.Animation_ZoomLight);  
10           //修改窗口的透明度,从而使Activity背景变暗
11 WindowManager.LayoutParams params=getActivity().getWindow().getAttributes();
12 params.alpha=0.7f; 13 getActivity().getWindow().setAttributes(params); 14 //点击其他地方消失 15 popupWindow_view.setOnTouchListener(new OnTouchListener() { 16 @Override 17 public boolean onTouch(View v, MotionEvent event) { 18 // TODO Auto-generated method stub 19 closePopupWindow(); 20 return false; 21 } 22 }); 23 } 24 /*** 25 * 获取PopupWindow实例 26 */ 27 private void getPopupWindow() { 28 29 if (null != popupWindow) { 30 closePopupWindow(); 31 return; 32 } else { 33 initPopuptWindow(); 34 } 35 } 36 /** 37 * 关闭窗口 38 */ 39 private void closePopupWindow() 40 { 41 if (popupWindow != null && popupWindow.isShowing()) { 42 popupWindow.dismiss(); 43 popupWindow = null; 44 WindowManager.LayoutParams params=getActivity().getWindow().getAttributes(); 45 params.alpha=1f; 46 getActivity().getWindow().setAttributes(params); 47 } 48 }

 

posted on 2015-11-11 17:04  Jasonxcj  阅读(899)  评论(0编辑  收藏  举报

导航