为popupwindow添加背景变暗的效果

产生背景变暗效果

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);
            });
    原文作者:白色相簿
    原文地址: https://www.jianshu.com/p/2f4cc426f683
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞