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的使用的更多相关文章

  1. Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder

    Stack Overflow 排错翻译  - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...

  2. Android中的AlertDialog使用示例五(自定义对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  3. android 弹出AlertDialog的学习案例

    我在编写的时候,测试的关键代码: AlertDialog.Builder builder=new AlertDialog.Builder(MainPointListActivity.this); bu ...

  4. 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 ...

  5. setView的AlertDialog在受到二次点击后出错

    错误报告: 10-21 13:11:16.009: E/AndroidRuntime(27937): FATAL EXCEPTION: main10-21 13:11:16.009: E/Androi ...

  6. 关于AlertDialog.Builder(Context context)中所应传入的context

    错误报告: 10-20 14:34:46.565: E/AndroidRuntime(23098): FATAL EXCEPTION: main10-20 14:34:46.565: E/Androi ...

  7. 安卓 自定义AlertDialog对话框(加载提示框)

    AlertDialog有以下六种使用方法: 一.简单的AlertDialog(只显示一段简单的信息) 二.带按钮的AlertDialog(显示提示信息,让用户操作) 三.类似ListView的Aler ...

  8. Android AlertDialog去除黑边白边自定义布局(转)

    LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.test_alert ...

  9. Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)

    前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...

  10. Android中的AlertDialog使用示例四(多项选择确定对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

随机推荐

  1. 初步学习Axure---整理了一下自己两周的学习成果:动态面板

    自己无意间发现了做原型设计的工具--Axure,所以就自学了一点皮毛.最近时间比较充裕,就把自己现学现卖的东西整一整. 作品比较简单,没有技术可言,根据用户和开发需求,利用动态面板和一些点击事件完成了 ...

  2. Spring cloud父项目的建立

    1.建立一个maven项目 注意建立项目的时候.选择pom的包 2.添加架包 <project xmlns="http://maven.apache.org/POM/4.0.0&quo ...

  3. Project Euler 43 Sub-string divisibility

    题意: 1406357289是一个0至9全数字数,因为它由0到9这十个数字排列而成:但除此之外,它还有一个有趣的性质:子串的可整除性.记d1是它的第一个数字,d2是第二个数字,依此类推,我们注意到: ...

  4. [网络流24题] 最长k可重区间集问题 (费用流)

    洛谷传送门 LOJ传送门 很巧妙的建图啊...刚了$1h$也没想出来,最后看的题解 发现这道题并不类似于我们平时做的网络流题,它是在序列上的,且很难建出来二分图的形. 那就让它在序列上待着吧= = 对 ...

  5. linux下RTP编程(使用JRTPLIB)(转)

    流媒体指的是在网络中使用流技术传输的连续时基媒体,其特点是在播放前不需要下载整个文件,而是采用边下载边播放的方式,它是视频会议.IP电话等应用场合的技术基础.RTP是进行实时流媒体传输的标准协议和关键 ...

  6. springboot 不使用前端模板直接跳转页面

    1.创建springboot项目 2.在resource 下创建pages文件夹,存放所有页面 3.编写后台代码 4.访问http://localhost:8080/index,即可跳转到页面

  7. Google Spanner (中文版)

    温馨提示:本论文由厦门大学计算机系林子雨翻译自英文论文,转载请注明出处,仅用于学习交流,请勿用于商业用途. [本文翻译的原始出处:厦门大学计算机系数据库实验室网站林子雨老师的云数据库技术资料专区htt ...

  8. rabbitMQ学习笔记(四) 发布/订阅消息

    前面都是一条消息只会被一个消费者处理. 如果要每个消费者都处理同一个消息,rabbitMq也提供了相应的方法. 在以前的程序中,不管是生产者端还是消费者端都必须知道一个指定的QueueName才能发送 ...

  9. ASP.Net Cookie总结

    Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一 ...

  10. nyoj Wythoff Game(暴力枚举)

    Wythoff Game  ms |   KB 描写叙述 近期ZKC同学在学博弈,学到了一个伟大的博弈问题--威佐夫博弈. 相信大家都学过了吧?没学过?没问题.我将要为你讲述一下这个伟大的博弈问题. ...