Android开发学习:[6]AlertDialog
1、首先我们在界面布局上面布局四个按钮
![Android开发学习:[6]AlertDialog](https://exp-picture.cdn.bcebos.com/b87bd38920c5260fe6bc4239d2de4507890189dc.jpg)
3、然后我们敲入AlterDialog代码://显示带中立,取消,确定的提示框 button3.setOnClickListener(new View.OnCl足毂忍珩ickListener() { @Override public void onClick(View v) { AlertDialog alertDialog=new AlertDialog.Builder(MainActivity.this).create(); //alertDialog.setIcon(R.drawable.desert); alertDialog.setTitle("System Information:"); alertDialog.setMessage("Dialog with cancel confirm and neutral button!"); //添加取消按钮 alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"You clicked the Cancel Button",Toast.LENGTH_LONG).show(); } }); //添加确定按钮 alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,"Confirm",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"You clicked the Confirm Button",Toast.LENGTH_LONG).show(); } }); //添加中立按钮 alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,"neutral",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"You clicked the neutral Button",Toast.LENGTH_LONG).show(); } }); alertDialog.show(); } });图片请注意看行号
![Android开发学习:[6]AlertDialog](https://exp-picture.cdn.bcebos.com/8974c38a59de4507fa88a7c35e413a8ca70885dc.jpg)
4、现在我们点击运行按钮,运行此程序,界面如下图所示
![Android开发学习:[6]AlertDialog](https://exp-picture.cdn.bcebos.com/89402670d5413a8cd0813abc1ffc508c9ace81dc.jpg)
6、点击任意一个回出现Toast显示你点击了哪个按钮
![Android开发学习:[6]AlertDialog](https://exp-picture.cdn.bcebos.com/a749bb0f94fc508ce147584b01775ddd894cfddc.jpg)
7、后面将继续介绍后续的三个AlterDialog欢迎继续关注。