BottomSheetDialog设置透明背景,默认情况下的背景是白色的
answerSheetDialog = new BottomSheetDialog(testModeActivity);
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_question_answersheet, null, false);
answerSheetDialog.setContentView(inflate);
answerSheetDialog.setCanceledOnTouchOutside(true);
answerSheetDialog.setCancelable(true);
answerSheetDialog.show();
//设置透明背景
answerSheetDialog.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(android.R.color.transparent);
以上一段代码就可以改变默认的白色背景
注意:设置代买必须在下面方法的后面才可以!!!(否则dialog的内容VIew还未赋值,会出现异常信息!)
answerSheetDialog.setContentView(inflate);
//设置透明背景
answerSheetDialog.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(android.R.color.transparent);