1.popuwindow弹出时,弹窗背景是全透明的,可以在其弹出时添加如下代码:
ColorDrawable cds = new ColorDrawable(0x000000);
popupw.setBackgroundDrawable(cds);
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha = 0.2f;
getWindow().setAttributes(lp);//改变透明度,并重新设置
并监听popuwindow消失事件,如果其消失,恢复背景透明度
popupw.setOnDismissListener(new OnDismissListener(){
//在dismiss中恢复透明度
public void onDismiss(){
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
}
});
2.直接把popuwindow背景设置成半透明颜色
ColorDrawable dw = new ColorDrawable(0xb0000000); popupWindow.setBackgroundDrawable(dw);