Android中dialog修改默认背景色的透明的

public class MyDialog extends Dialog {
public MyDialog(@NonNull Context context) {
super(context);
getWindow().getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
layoutParams.dimAmount = 0.1f;//指定透明的,下图中的1这个部分在这里插入图片描述
getWindow().setAttributes(layoutParams);
getWindow().setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.bg));//指定背景,下图中的2
}

猜你喜欢

转载自blog.csdn.net/genmenu/article/details/96610171