【发布时间】:2020-07-20 12:55:39
【问题描述】:
我在使用 java 的 Android Studio 中,并且有一个带有两个按钮的 AlertDialog。我的问题是:当我按下背景而不是按钮时,我可以禁用该对话框不会消失吗?
我使用这段代码来显示对话框:
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.AlertDialogTheme);
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_wellcome_start_dialog,(ConstraintLayout)findViewById(R.id.layoutDialogConstrainer));
builder.setView(view);
((TextView) view.findViewById(R.id.textTitle)).setText(getResources().getString(R.string.titel));
((TextView) view.findViewById(R.id.textMessage)).setText(getResources().getString(R.string.startinfoone));
((Button) view.findViewById(R.id.buttonYes)).setText(getResources().getString(R.string.ok));
((Button) view.findViewById(R.id.buttonNo)).setText(getResources().getString(R.string.ueberspringen));
((ImageView) view.findViewById(R.id.imageIcon)).setImageResource(R.drawable.ic_info);
final AlertDialog alertDialog = builder.create();
view.findViewById(R.id.buttonYes).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
weiter();
}
});
view.findViewById(R.id.buttonNo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null){
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
谢谢!
【问题讨论】:
-
alertDialog.setCanceledOnTouchOutside(false).
标签: android background click android-alertdialog