android 遮罩窗口,Andriod PopupWindow 实现遮罩效果
效果图:PopupWindow是没有遮罩层效果的,这样看起来会显得很突兀。那么,如果要给PopupWindow添加遮罩层,又该如何实现呢?下面是实现的代码:private void backgroundAlpha(float f) {WindowManager.LayoutParams lp = ((Activity)context).getWindow().getAttributes();lp.
·
效果图:
PopupWindow是没有遮罩层效果的,这样看起来会显得很突兀。那么,如果要给PopupWindow添加遮罩层,又该如何实现呢?下面是实现的代码:
private void backgroundAlpha(float f) {
WindowManager.LayoutParams lp = ((Activity)context).getWindow().getAttributes();
lp.alpha = f;
((Activity)context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//背景变暗
((Activity)context).getWindow().setAttributes(lp);
}
上述方法通过在改变了窗口的透明度,只要在PopupWindow显示/隐藏时调用该方法降低/还原窗口透明度,就能达到遮罩层的效果。
// dismiss
backgroundAlpha(1.0f);
//show
backgroundAlpha(0.5f);
更多推荐
已为社区贡献4条内容
所有评论(0)