public class AlertDialog_main1 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert_dialog_main1);
final Context ctx = AlertDialog_main1.this;
AlertDialog.Builder builder = new AlertDialog.Builder(AlertDialog_main1.this);
builder.setIcon(R.drawable.info)
.setTitle("系统提示")
.setMessage("这是一个最普通的AlertDialog,\n带有三个按钮,\n带有三个按钮,分别是取消,普通和确定");
//取消按钮
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(ctx, "你点击了取消按钮", Toast.LENGTH_SHORT).show();
}
});
//确定按钮
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(ctx, "你点击了确定按钮", Toast.LENGTH_SHORT).show();
}
});
//普通按钮
builder.setNeutralButton("普通按钮", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(ctx, "你点击了普通按钮", Toast.LENGTH_SHORT).show();
}
});
//创建AlertDialog对象
AlertDialog alert = builder.create();
alert.show();//显示对话框
}
}
Android AlertDialog普通对话框练习
最新推荐文章于 2022-04-26 12:44:43 发布