Android学习笔记:[4]AlertDialog警告对话框
1、新建一个Android Application Project:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/604e9556ad042e68925c915285f85856d43dd108.jpg)
2、将这个Android Application Project命名为:AertDialog
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/50a010f85856d53d2291185a47d2bb665059ca08.jpg)
3、打开其中的MainActivity:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/5917cb3da824d8e940677bd5da598540112ac808.jpg)
4、首先声明成员变量:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/d9a8d2d2bb6651590af5d0998fe23ea23b42c708.jpg)
5、设置提示信息,setPositiveButton():给对话框添加”Yes”按钮,setNegativeButton():给对话框添加”No”按钮:,确定按钮:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/50189b40102a04e2ac17faf12b7aa010bd33c208.jpg)
6、调用Builder的create( )方法,调用AlertDialog的show( )方法显示对话框:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/05a320a23a42a07a35a57c80673834bb18efc108.jpg)
7、activity.xml中的布局情况:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/3b03be7aa010bc337b8df40892efa25f0d143f09.jpg)
8、在虚拟机中运行一下,右击该Project选择“运行方式“,选择”Android Application“:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/bd72f23834bb19ef38eacca7497bd28287893a09.jpg)
9、点击按钮,则出现对话框,选择不同选项,字符出现不同情况:
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/35fa07efa25f0c145ece12310d89a146b6b13809.jpg)
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/a31e1214c27bd282183c61f53cb1eef97ebd3609.jpg)
![Android学习笔记:[4]AlertDialog警告对话框](https://exp-picture.cdn.bcebos.com/0d55dc7bd28286893ef3770265f97fbd4d7c3709.jpg)