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. 编译VTK的MFC库

    原文链接:http://blog.csdn.net/left_la/article/details/7069708 本人做了少量修改! Win7 + VS2010 + CMake2.8.6 + VTK ...

  2. Block Functionality

    Block Functionality A block is an anonymous inline collection of code that: Has a typed argument lis ...

  3. jq DataTable

    DataTables(http://datatables.club/index.html)应该是我到目前为止见过的,功能最强大的表格解决方案(当然,不计算其它整套框架中的table控件在内). 先把它 ...

  4. Python数据结构1-----基本数据结构和collections系列

    1.基本数据结构 整型.浮点型.字符串.元祖.列表.字典.集合 2.高级数据结构 (collections模块) (1)计数器(counter):对字典的补充,用于追踪值的出现次数. [具备字典所有的 ...

  5. Performance Co-Pilot

    Install Performance Co-Pilot 提前安装依赖 [root@iZrj97j6t7ih9hgz1me35hZ ~]# cat install.sh yum install -y ...

  6. 【JavaScript框架封装】在实现一个自己定义类似于JQuery的append()函数的时候遇到的问题及解决方案

    主要问题: 在刚开始创建了这个函数之后,使用的时候,总是会出现一个问题,就是按照正常步骤给一个ID选择器添加子节点的时候正常,但是到了给一个class选择器的元素添加的时候始终只能添加一个. 下面是我 ...

  7. Spring环境搭建及简单demo

    1. Spring框架简介(以下这段话可用于面试求职) Spring为JavaEE开发提供了一个轻量级的解决方案,主要表现为, IOC(或者叫做DI)的核心机制,提供了bean工厂(Spring容器) ...

  8. Java中发邮件的6种方法

    1.官方标准JavaMail Sun(Oracle)官方标准,功能强大,用起来比较繁琐. 官方资料:http://www.oracle.com/technetwork/java/javamail/in ...

  9. [Linux]第三部分-学习Shell和Shell脚本

    vim 高级的 vii o a 进入编辑模式 esc进入一般模式:wq离开alias vi='vim' 使用vim打开viv块选择 y复制反白,d删除反白在vi中打开一个文件后,可以使用 sp fil ...

  10. NHibernate之旅(18):初探代码生成工具使用

    本节内容 引入 代码生成工具 结语 引入 我们花了大量的篇幅介绍了相关NHibernate的知识.一直都是带着大家手动编写代码,首先创建数据库架构.然后编写持久化类和映射文件,最后编写数据操作方法.測 ...