Android之使用PopupWindow让背景变黯但是华为手机出现屏幕一闪一闪问题解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011068702/article/details/81225122

1、问题

我们使用PopupWindow设置背景变黯(代码如下),但是部分华为手机出现屏幕一闪一闪

	//设置背景透明度
	public void setBackgroundAlpha(float bgAlpha) {
		WindowManager.LayoutParams lp = CurrentActivity.this.getWindow()
				.getAttributes();
		lp.alpha = bgAlpha;
		CurrentActivity.this.getWindow().setAttributes(lp);
	}

2、解决办法

我们可以找到windowManager类里面下面的属性

        /** Window flag: everything behind this window will be dimmed.
         *  Use {@link #dimAmount} to control the amount of dim. */
        public static final int FLAG_DIM_BEHIND        = 0x00000002;

意思是 这个窗口后面的所有东西都会变暗

所以设置背景透明度代码改成这样就行了

	public void setBackgroundAlpha(float bgAlpha) {
		WindowManager.LayoutParams lp = CurrentActivity.this.getWindow()
				.getAttributes();
		lp.alpha = bgAlpha;
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		CurrentActivity.this.getWindow().setAttributes(lp);
	}

猜你喜欢

转载自blog.csdn.net/u011068702/article/details/81225122
今日推荐