android学习之AlertDialog使用
来源:互联网 发布:田柾国金泰亨感情知乎 编辑:程序博客网 时间:2024/06/07 10:24
原文地址:http://developer.android.com/intl/zh-cn/guide/topics/ui/dialogs.html
创建AlertDialog
// 1. Instantiate an AlertDialog.Builder with its constructorAlertDialog.Builder builder = new AlertDialog.Builder(getActivity());// 2. Chain together various setter methods to set the dialog characteristicsbuilder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);// 3. Get the AlertDialog from create()AlertDialog dialog = builder.create();
添加如图所示的按钮
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());// Add the buttonsbuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button }});builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog }});// Set other dialog properties...// Create the AlertDialogAlertDialog dialog = builder.create();
set…Button() 方法需要一个按钮标题(由字符串资源提供)和一个 DialogInterface.OnClickListener,后者用于定义用户按下该按钮时执行的操作。
您可以添加三种不同的操作按钮:
肯定
您应该使用此按钮来接受并继续执行操作(“确定”操作)。
否定
您应该使用此按钮来取消操作。
中性
您应该在用户可能不想继续执行操作,但也不一定想要取消操作时使用此按钮。 它出现在肯定按钮和否定按钮之间。 例如,实际操作可能是“稍后提醒我”。
对于每种按钮类型,您只能为 AlertDialog 添加一个该类型的按钮。也就是说,您不能添加多个“肯定”按钮。
添加列表
可通过 AlertDialog API 提供三种列表:
- 传统单选列表
- 永久性单选列表(单选按钮)
- 永久性多选列表(复选框)
0 0
- android学习之AlertDialog使用
- android学习之使用AlertDialog创建对话框
- Android学习之AlertDialog
- Android学习之AlertDialog
- android之使用AlertDialog
- Android学习笔记之AlertDialog
- Android学习之自定义AlertDialog
- Android之AlertDialog的使用
- 25、Android之AlertDialog使用
- Android学习:用户界面UI之AlertDialog
- Android基础之AlertDialog(对话框)的学习
- Android开发入门之AlertDialog使用总结
- Android之AlertDialog(弹出式对话框)的使用
- Android之AlertDialog的基础使用
- Android AlertDialog学习
- Android 学习--alertdialog主题
- android 之自定义 AlertDialog
- android 组件之 alertDialog
- 浅谈设计模式之单例模式
- 告别了三年,总结和回顾
- 八大排序算法
- 对话Linus Torvalds:大多黑客甚至连指针都未理解
- 手势识别器(UIGestureRecognizer)- UIPinchGestureRecognizer(捏合)
- android学习之AlertDialog使用
- 不知所措
- Android WCF Restful 服务续
- CAP定理
- java数组的使用
- ios 动态添加了按钮,绑定同一个点击事件,如何判断点击的是哪个?
- 知我意,感君怜,此情须问天!
- 偶尔翻检几本数学方面堪称经典的中文教材发现错误
- 【不为人知的编码】 Javascript“整型数据趋向”操作符