popwindow显示出现黑色闪屏效果

在用popwindow时,如果退出当前activity时闪现了一下黑屏,但是程序也是正常的,并没有崩溃,这里的问题在于消失时并没有清除所有的flag


/** 

 * 
 * @author lw
 * 编写时间: 2016年11月11日下午3:32:51
 * 类说明 :  www.liuwei1995.com
 * {@linkplain WindowManager.LayoutParams lp = context.getWindow().getAttributes();
lp.alpha = 1.0f;
context.getWindow().setAttributes(lp);
context.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);}
 */
public class LwPopupWindow {
private View inflate;
private PopupWindow window;
public LwPopupWindow(Context context, int LayoutId) {
this.inflate = LayoutInflater.from(context).inflate(LayoutId, null);
}
public void showPopUp(final Activity context,final View parent) {//parent  显示的位置    例如点击的button
if (window == null) {
window = new PopupWindow(inflate, 160, LayoutParams.WRAP_CONTENT);//inflate 要显示的布局

// 设置整个popupwindow的样式。
window.setBackgroundDrawable(context.getResources().getDrawable(
R.drawable.ic_launcher));//必填


// 使窗口里面的空间显示其相应的效果,比较点击button时背景颜色改变。
// 如果为false点击相关的空间表面上没有反应,但事件是可以监听到的。
// listview的话就没有了作用。
WindowManager.LayoutParams lp = context.getWindow().getAttributes();
lp.alpha = 1.0f;
context.getWindow().setAttributes(lp);

window.setFocusable(true);// 如果不设置setFocusable为true,popupwindow里面是获取不到焦点的,那么如果popupwindow里面有输入框等的话就无法输入。
window.setOutsideTouchable(true);
window.setAnimationStyle(android.R.style.Animation_Dialog); // 设置显示动画  
int[] location = new int[2];
parent.getLocationOnScreen(location);



window.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
// ----------------------------重点--------------------------------
WindowManager.LayoutParams lp = context.getWindow().getAttributes();
lp.alpha = 1.0f;
context.getWindow().setAttributes(lp);
context.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
});
}
window.showAsDropDown(parent);
}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值