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

 时间:2026-04-23 18:31:13

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警告对话框

  • 如何修改文件的扩展名\如何隐藏或显示扩展名
  • 如何显示所有文件类型的扩展名?
  • 如何复制文件或文件夹路径
  • if-else_if 判断否则与判断
  • excel如何添加工作簿连接快捷键
  • 热门搜索
    我运动我健康手抄报 关于菊花的手抄报 英语手抄报花边边框 体育节手抄报 环保手抄报资料大全 安全意识手抄报 快乐暑假手抄报内容 预防流感手抄报 预防疾病手抄报内容 遵纪守法手抄报内容