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实现方法为建造者模式. ...
随机推荐
- winform右键菜单
public partial class Form1 : Form { ContextMenuStrip cms; Bitmap bm ; public Form1() { InitializeCom ...
- vue1 到 vue2 v-el变成ref
vue1的写法 div class="menu-wrapper" v-el="menu-wrapper"> <ul class="menu ...
- 6 Python+Selenium的元素定位方法(CSS)
[环境] python3.6+selenium3.0.2+Firefox50.0+win7 [定位方法] 1.方法:find_element_by_css_selector('xx') CSS的语法比 ...
- 【路飞学城Day170】算法小结
Evernote Export 算法的思想是能省则省,内存能少则少,时间运行能少尽量少 堆排序的时间复杂度O(nlogn) 堆排序的内置模块heapq 常用函数 heapify(x) heappush ...
- SQL SEVER (ROLLUP与CUBE,ROW_NUMBER())使用方法
1.建立测试专用数据: if object_id('TESTDB') is not null drop table TESTDB ), B INT) insert into TESTDB union ...
- hibernate中session的get和load方法的区别和联系:
1. get:及时加载,调用到get方法时立即向数据库查询(在没有session缓存的请况). 2. load:默认使用懒加载,当用到数据的时候才向数据库查询(在没有session缓存的请况). 3. ...
- Project Euler 29 Distinct powers( 大整数质因数分解做法 + 普通做法 )
题意: 考虑所有满足2 ≤ a ≤ 5和2 ≤ b ≤ 5的整数组合生成的幂ab: 22=4, 23=8, 24=16, 25=3232=9, 33=27, 34=81, 35=24342=16, 4 ...
- django rest-farme-work 的使用(1)
Django REST框架是一个用于构建Web API的强大且灵活的工具包 您可能想要使用REST框架的一些原因: 可浏览性 身份认证 支持ORM和非ORM的序列化 良好的文档支持 安装初步 pip ...
- php中的form表单
表单处理 表单的概念在生活中很常见,就像是问卷调查表一样,别人先把问卷发给你,你照着问卷的要求填写,完事过后再将填完的问卷发给别人,从而达到一个将别人需要的信息传递给别人的一种方式. 传统的网页大多数 ...
- jQuery(Dom节点操作)