AlertDialog的使用
1.Alertdialog的几种形式:

2.第一种:简单对话框

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
localBuilder.setTitle("简单对话框");
localBuilder.setIcon(R.mipmap.ic_launcher);
localBuilder.setMessage("提示信息?");
localBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
/**
* 确定操作
* */
}
});
localBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
/**
* 确定操作
* */
}
}); /***
* 设置点击返回键不会消失
* */
localBuilder.setCancelable(false).create(); localBuilder.show();
3.第二种:列表式对话框

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
final String[] arrayOfString = { "选项1", "选项2", "选项3", "选项4", "选项5", "选项6" };
localBuilder.setTitle("简单列表对话框").setIcon(R.mipmap.ic_launcher).setItems(arrayOfString, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
/**
* 操作
* */
Toast.makeText(MainActivity.this, "你选择了: " + arrayOfString[paramAnonymousInt], Toast.LENGTH_SHORT).show();
/**
* 列表对话框不加这句,点击选择后也后不会消失
* */
paramAnonymousDialogInterface.dismiss();
}
}).create().show();
4.第三种形式:单选对话框

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
final String[] arrayOfString = { "1", "2", "3", "4", "5", "6"};
localBuilder.setTitle("单选对话框").setIcon(R.mipmap.ic_launcher);
localBuilder.setSingleChoiceItems(arrayOfString, 3, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
/**
* 操作
* */
Toast.makeText(MainActivity.this, "你选择了: " + arrayOfString[paramAnonymousInt], Toast.LENGTH_SHORT).show(); paramAnonymousDialogInterface.dismiss();
}
}).setCancelable(false).create().show();
5.第四种形式:多选对话框

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
final String[] arrayOfString = { "0", "1", "2", "3", "4" };
localBuilder.setTitle("多选对话框").setIcon(R.mipmap.ic_launcher);
localBuilder.setMultiChoiceItems(arrayOfString, new boolean[] { true, true, true, false, true }, new DialogInterface.OnMultiChoiceClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt, boolean paramAnonymousBoolean)
{
if (paramAnonymousBoolean) {
Toast.makeText(MainActivity.this, "你选择了: " + arrayOfString[paramAnonymousInt], Toast.LENGTH_SHORT).show(); }
}
}).setPositiveButton("提交", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
paramAnonymousDialogInterface.dismiss();
}
}).create().show();
6.第五种形式:自定义对话框

AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
localBuilder.setTitle("自定义列表对话框").setIcon(R.mipmap.ic_launcher);
localBuilder.setView(getLayoutInflater().inflate(R.layout.layout, null));
localBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
/**
*
* 操作
* */
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
/**
*
* 操作
* */
}
}).create().show();
自定义列表对话框:
AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
final String[] arrayOfString = { "0", "1", "2", "3", "4", "5", "6", "7", "8" };
localBuilder.setTitle("自定义列表对话框").setIcon(R.mipmap.ic_launcher);
localBuilder.setAdapter(new ArrayAdapter(this,R.layout.support_simple_spinner_dropdown_item, arrayOfString), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
{
Toast.makeText(MainActivity.this, "你选择了 : " + arrayOfString[paramAnonymousInt], Toast.LENGTH_SHORT).show();
}
}).create().show();
<AlertDialog 主题颜色>
传统主题:
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_TRADITIONAL)
深黑色主题:
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_HOLO_DARK);
蓝色主题:
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_HOLO_LIGHT);
深色主题:
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_DARK);
浅蓝主题:
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
AlertDialog的使用的更多相关文章
- Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder
Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...
- Android中的AlertDialog使用示例五(自定义对话框)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...
- android 弹出AlertDialog的学习案例
我在编写的时候,测试的关键代码: AlertDialog.Builder builder=new AlertDialog.Builder(MainPointListActivity.this); bu ...
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments
The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i ...
- setView的AlertDialog在受到二次点击后出错
错误报告: 10-21 13:11:16.009: E/AndroidRuntime(27937): FATAL EXCEPTION: main10-21 13:11:16.009: E/Androi ...
- 关于AlertDialog.Builder(Context context)中所应传入的context
错误报告: 10-20 14:34:46.565: E/AndroidRuntime(23098): FATAL EXCEPTION: main10-20 14:34:46.565: E/Androi ...
- 安卓 自定义AlertDialog对话框(加载提示框)
AlertDialog有以下六种使用方法: 一.简单的AlertDialog(只显示一段简单的信息) 二.带按钮的AlertDialog(显示提示信息,让用户操作) 三.类似ListView的Aler ...
- Android AlertDialog去除黑边白边自定义布局(转)
LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.test_alert ...
- Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)
前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...
- Android中的AlertDialog使用示例四(多项选择确定对话框)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...
随机推荐
- ZBrush的双十一来了,然鹅...
不管是“光棍节”还是“剁手节” 似乎和我都没有什么关系 事实证明,我错了 今早竟然有不识趣的人发红包祝我单身快乐 纳尼,这是唱的哪一出? 我能直接怼回去,说不领么? 但好像又不是我的风格 哎,一个红包 ...
- 点击之后上传图片到页面 input type="file" 样式
<!DOCTYPE html><head> <meta http-equiv="Content-Type" content="text/ht ...
- ajax发送请求是图标转圈圈实现
css部分 .load-img{ //控制图标大小width:40px;height:40px;margin:100px;border-radius:50%;-webkit-animation:cir ...
- Javaee 内部引用
1.final修饰类,修饰方法,修饰变量有什么特点? final修饰的类不能被继承太监类,可以被继承使用但不能修改,如果父类没有final修饰的方法子类可以添加上,成员变量需要在建类前被赋值且不能改动 ...
- [USACO08NOV]奶牛混合起来Mixed Up Cows(状态压缩DP)
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- Oracle与Mysql内嵌游标的使用示例
Oracle 游标用For循环比较简单,Mysql也是最近才开始用,感觉稍微麻烦一点,下边直接上代码: ------------------------------------------------ ...
- OOP 面向对象 七大原则 (一)
OOP 面向对象 七大原则 (一) 大家众所周知,面向对象有三大特征继承封装多态的同时,还具有这七大原则,三大特征上一篇已经详细说明,这一篇就为大家详解一下七大原则: 单一职责原则,开闭原则,里氏 ...
- asp.net-EF事物与存储过程
FK_Equipment_EquipmentClass 这个是sql中的命名规范,外键名称在前面,主键名称在后面 EF事务的代码 DbTransaction tran = null; try { ne ...
- 计算机网络系统--常用DOS命令
01.名称:md 用法:md “文件夹名” 用处:批量建立文件夹 02.关机命令 shutdown At 18:00 shutdown –s 18:00关机 shutdown -s -t 3 ...
- easy-ui采坑事件
新用户首次登陆修改密码 imput标签中使用easyui自带的class="easyui-passwordbox"可以是密码隐藏变成黑点但是无法禁用输入法,然后果断的加了一个typ ...