设置窗口透明度,Activity窗口背景变灰

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31028313/article/details/80688102
   public static void setWindowAlpha(Activity activity, float alpha) {
        if (alpha < 0 || alpha > 1) return;
        WindowManager.LayoutParams windowLP = activity.getWindow().getAttributes();
        windowLP.alpha = alpha;
        if (alpha == 1) {
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//不移除该Flag的话,在有视频的页面上的视频会出现黑屏的bug
        } else {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//此行代码主要是解决在华为手机上半透明效果无效的bug
        }
        activity.getWindow().setAttributes(windowLP);
    }

猜你喜欢

转载自blog.csdn.net/qq_31028313/article/details/80688102