1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| /** * 设置页面的昏暗度 * 主要作用于:弹窗时设置宿主Activity的背景色 * @param bgDimAmount */ public static void setBackgroundDimAmount(Activity activity, float bgDimAmount){ WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); lp.dimAmount = bgDimAmount; Window window = activity.getWindow(); if(window!=null){ if(bgDimAmount == 1){ window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); }else { window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } window.setAttributes(lp); } }
/** * 设置页面的透明度 * 主要作用于:弹窗时设置宿主Activity的背景色 * @param bgAlpha 1表示不透明 */ public void setBackgroundAlpha(float bgAlpha) { Dialog dialog = getDialog(); if(dialog!=null){ Window window = dialog.getWindow(); if(window!=null){ WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.alpha = bgAlpha; if (bgAlpha == 1) { //不移除该Flag的话,在有视频的页面上的视频会出现黑屏的bug window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } else { //此行代码主要是解决在华为手机上半透明效果无效的bug window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } window.setAttributes(lp); } } }
|