androiddialog弹出框有哪些

2022-04-12 社会 71阅读
privatevoiddialog1(){
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);//先得到构造器
builder.setTitle("提示");//设置标题
builder.setMessage("是否确认退出?");//设置内容
builder.setIcon(R.mipmap.ic_launcher);//设置图标,图片id即可
builder.setPositiveButton("确定",newDialogInterface.OnClickListener(){//设置确定按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();//关闭dialog
Toast.makeText(MainActivity.this,"确认"+which,Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消",newDialogInterface.OnClickListener(){//设置取消按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();
Toast.makeText(MainActivity.this,"取消"+which,Toast.LENGTH_SHORT).show();
}
});

builder.setNeutralButton("忽略",newDialogInterface.OnClickListener(){//设置忽略按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();
Toast.makeText(MainActivity.this,"忽略"+which,Toast.LENGTH_SHORT).show();
}
});
//参数都设置完成了,创建并显示出来
builder.create().show();
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com