【Android】AlertDalog对话框
来源:互联网 发布:c 并发编程实战 pdf 编辑:程序博客网 时间:2024/06/14 21:18
在做Android开发的时候经常会遇到需要提醒用户选择或操作的情况,这时候我们可以创建一个AlertDalog来使用。
new AlertDalog.Builder()时可以通过方法链来进行使用,也可以声明AlertDalog变量来接收使用。
一、通过声明一个AlertDalog变量定义对话框(带标题、内容、一个按钮)
<span style="white-space:pre"></span>private AlertDialog.Builder alertDialog; alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("我是标题"); alertDialog.setMessage("我是内容"); alertDialog.setPositiveButton("确定", null);//第二个参数为事件监听器 alertDialog.show();
二、通过方法链来定义对话框(标题、标题图标、输入框、三个按钮)
<span style="white-space:pre"></span>new AlertDialog.Builder(this) .setTitle("请输入") .setIcon(R.drawable.wifi) .setView(new EditText(this))//通过setView方法可以自定义显示在对话框中的组件、例如EditText、DatePicker等 .setPositiveButton("确认输入",null) .setNegativeButton("取消输入",null)<span style="white-space:pre"></span>.show();
三、定义三个按钮的对话框
new AlertDialog.Builder(this); .setTitle("请确定选择"); .setMessage("选择是否或取消"); .setPositiveButton("是", null); .setNegativeButton("否", null); .setNeutralButton("取消", null); .show();
四、单选框
<span style="white-space:pre"></span>new AlertDialog.Builder(this) .setTitle("单选框") .setSingleChoiceItems(new String[]{"选项一", "选项二", "选项三"}, 0, null) .setNegativeButton("取消选择",null) .show();
五、多选框
<span style="white-space:pre"></span>new AlertDialog.Builder(this) .setTitle("多选框") .setMultiChoiceItems(new String[]{"多选一","多选二","多选三","多选四"},null,null) .setPositiveButton("确定选择",null) .setNegativeButton("取消选择",null) .show();
六、列表框
<span style="white-space:pre"></span>new AlertDialog.Builder(this) .setTitle("列表框") .setItems(new String[]{"列表一","列表二","列表三"},null) .show();
0 0
- 【Android】AlertDalog对话框
- Android对话框
- Android对话框
- android 对话框
- android 对话框
- Android对话框
- Android对话框
- Android对话框
- Android对话框
- android对话框
- Android对话框
- android对话框
- Android对话框
- Android对话框
- android对话框
- android对话框
- Android对话框
- android 对话框
- logcat命令行输出tag为Mylistview,日志级别为info,以及多个tag的写法
- 面向对象杂想:
- arduino五天小结
- 非递归实现归并排序算法
- 详细介绍Java中的堆、栈和常量池
- 【Android】AlertDalog对话框
- Ubuntu vi与vim使用
- Connecting Oracle to PostgreSQL using Oracle Gateways
- 使用Java完成《算法导论》习题2.3-2
- Java解惑之try catch finally
- 设计模式之简单工厂模式
- AppStore 登录提示未知错误的解决办法
- SDP协议简述
- Windows 小知识点汇总