产生背景变暗效果
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.4f; //设置透明度
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setAttributes(lp);
关闭popupwindow时恢复
mPopupWindow.setOnDismissListener(() -> {
WindowManager.LayoutParams lp1 = getWindow().getAttributes();
lp1.alpha = 1f;
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setAttributes(lp1);
});