Android dialog changes the default background color to be transparent

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;//Specify transparent, the part 1 in the figure below getWindow().setAttributes(layoutParams); getWindow().setBackgroundDrawable( ContextCompat.getDrawable(context, R.drawable.bg ));//Specify the background, 2 in the figure below }





Insert picture description here


Guess you like

Origin blog.csdn.net/genmenu/article/details/96610171