华为手机popwindow背景不变暗的问题

PopupWindow popupWindow = new PopupWindow(this);
WindowManager.LayoutParams lp = getWindow().getAttributes();
//设置显示时的背景透明度0.7f
lp.alpha = 0.7f;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setAttributes(lp);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {    
    @Override
    public void onDismiss() {
          WindowManager.LayoutParams lp = getWindow().getAttributes();
          //dismiss后恢复1f
          lp.alpha = 1f;
          getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
          getWindow().setAttributes(lp);    
        }
});

关键代码:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

你可能感兴趣的:(华为手机popwindow背景不变暗的问题)