popupWindow弹出来后,背景变暗,半透明

 1 /**
 2      * 点击评分,如果评分后,显示的弹出框
 3      */
 4     private void showMakeGradeMarkedWindow() {
 5         View view = LayoutInflater.from(DetailActivity.this).inflate(
 6                 R.layout.grade_screen_marked, null);
 7         final PopupWindow mPopupWindow = new PopupWindow(view, 469, 280);
 8         mPopupWindow.setFocusable(true);
 9         ColorDrawable dw = new ColorDrawable(0xb0000000);
10         mPopupWindow.setBackgroundDrawable(dw);
11         mPopupWindow.showAtLocation(install, Gravity.CENTER, 0, 0);
12  
13         final RatingBar mraRatingBar = (RatingBar) view
14                 .findViewById(R.id.grade_screen);
15         mraRatingBar.setRating(4.5f);
16 //      mraRatingBar.setEnabled(false);
17         // 设置背景颜色变暗
18         WindowManager.LayoutParams lp = getWindow().getAttributes();
19         lp.alpha = 0.7f;
20         getWindow().setAttributes(lp);
21         mPopupWindow.setOnDismissListener(new OnDismissListener() {
22  
23             @Override
24             public void onDismiss() {
25                 WindowManager.LayoutParams lp = getWindow().getAttributes();
26                 lp.alpha = 1f;
27                 getWindow().setAttributes(lp);
28             }
29         });
30  
31     }

 当popupWindow消失后,监听其消失的方法,让背景恢复原样。

原文地址:https://www.cnblogs.com/xiaoliu66007/p/4834316.html