Android学习笔记:[4]AlertDialog警告对话框

 时间:2024-11-01 02:14:46

1、新建一个Android Application Project:

Android学习笔记:[4]AlertDialog警告对话框

2、将这个Android Application Project命名为:AertDialog

Android学习笔记:[4]AlertDialog警告对话框

3、打开其中的MainActivity:

Android学习笔记:[4]AlertDialog警告对话框

4、首先声明成员变量:

Android学习笔记:[4]AlertDialog警告对话框

5、设置提示信息,setPositiveButton():给对话框添加”Yes”按钮,setNegativeButton():给对话框添加”No”按钮:,确定按钮:

Android学习笔记:[4]AlertDialog警告对话框

6、调用Builder的create( )方法,调用AlertDialog的show( )方法显示对话框:

Android学习笔记:[4]AlertDialog警告对话框

7、activity.xml中的布局情况:

Android学习笔记:[4]AlertDialog警告对话框

8、在虚拟机中运行一下,右击该Project选择“运行方式“,选择”Android Application“:

Android学习笔记:[4]AlertDialog警告对话框

9、点击按钮,则出现对话框,选择不同选项,字符出现不同情况:

Android学习笔记:[4]AlertDialog警告对话框Android学习笔记:[4]AlertDialog警告对话框Android学习笔记:[4]AlertDialog警告对话框
热门搜索
月经期间怎样减肥最快 世家攻略 神奇宝贝白金光攻略 苏东坡简介 吞食天地3攻略 腹部怎样减肥 普陀山 攻略 云水谣攻略 汉之云攻略 短发怎么扎简单好看