popuwindow弹出时,背景半透明

来源:互联网 发布:网络运维方案 编辑:程序博客网 时间:2024/05/29 04:07

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);
     }
    });


0 0