我在某些操作之前创建了 AlertDialog,并且 AlertDialog 不会在操作之后关闭。
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View pbview = inflater.inflate(R.layout.progress_bar, null);
builder.setView(pbview);
builder.setCancelable(true);
builder.create().show();
//do some stuff
builder.create().dismiss();
}
顺便说一句,我的 AlertDialog 没有任何按钮。 我想制作没有按钮的 AlertDialog,并在操作结束时自动关闭。
编辑:我更改了实例名称。
最佳答案
同意@ρяσѕρєя K 创建一个 AlertDialog 实例并将您的代码修改为。
AlertDialog alert ;
alert = dlgAlert.create();
alert.show();
//do some stuff
alert.dismiss();
如果你想要一个自定义对话框,那么你可以使用这样的代码:-
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
关于Android 警报对话框不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20737139/