对话框通知(Dialog Notification)
来源:互联网 发布:c语言怎么做图形界面 编辑:程序博客网 时间:2024/04/25 18:37
当你的应用需要显示一个进度条或需要用户对信息进行确认时,可以使用对话框来完成。
下面代码将打开一个如右图所示的对话框:
new AlertDialog.Builder(context)
.setTitle("java培训")
.setCancelable(false)//设置不能通过“后退”按钮关闭对话框
.setMessage("浏览传智播客网站?")
.setPositiveButton("确认",
newDialogInterface.OnClickListener(){
publicvoid onClick(DialogInterfacedialoginterface,inti){
Uri uri =Uri.parse("http://www.itcast.cn/");//打开链接
Intentintent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
})
.setNegativeButton("取消", newDialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
})
.show();//显示对话框
上面代码采用的是一个链式调用,像setTitle()、setMessage()这些方法,他们的返回值都是当前对话框对象。
创建带单选项列表的对话框
下面代码将打开一个如右上图所示的选项列表对话框:
final String[] items ={"java", ".net", "php"};
new AlertDialog.Builder(SenderNotificationActivity.this).setTitle("选择语言")
.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item],
Toast.LENGTH_SHORT).show();
}
}).show();//显示对话框
下面代码将打开一个如右下图所示的带单选框的列表对话框:
final String[] items ={"java", ".net", "php"};
new AlertDialog.Builder(SenderNotificationActivity.this).setTitle("选择语言")
.setSingleChoiceItems(items, 1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item],
Toast.LENGTH_SHORT).show();
dialog.cancel();
}
}).show();//显示对话框
setSingleChoiceItems()的第二个参数是设置默认选项,
选项索引从0开始,-1代表不选择任何选项。
创建带多选项列表的对话框
下面代码将打开一个如右下图所示的多选项列表对话框:
final String[] items ={"java", ".net", "php"};
new AlertDialog.Builder(SenderNotificationActivity.this).setCancelable(false)
.setTitle("选择语言")
.setMultiChoiceItems(items, new boolean[]{false,true,false}, new DialogInterface.OnMultiChoiceClickListener() {
@Override
publicvoid onClick(DialogInterface dialog, int which, booleanisChecked) {
if(isChecked){
Toast.makeText(getApplicationContext(), items[which],
Toast.LENGTH_SHORT).show();
}
}
})
.setPositiveButton("确认",
newDialogInterface.OnClickListener(){
publicvoid onClick(DialogInterfacedialoginterface, inti){
dialoginterface.dismiss();
}
})
.show();//显示对话框
进度对话框(ProgressDialog)
ProgressDialog.STYLE_SPINNER 旋体进度条风格 (为默认风格)
ProgressDialog.STYLE_HORIZONTAL 横向进度条风格
- 对话框通知(Dialog Notification)
- Android对话框通知(Dialog Notification)
- Android 对话框通知(Dialog Notification)
- 系出名门Android(3) - 对话框(Dialog)和通知(Notification)
- 系出名门Android(3) - 对话框(Dialog)和通知(Notification)
- 系出名门Android(3) - 对话框(Dialog)和通知(Notification)
- 自定义Dialog、PopupWindow、通知Notification
- 从J2EE转向Android的第十天-----对话框(Dialog)和通知(Notification)
- 08-28 Dialog续篇、Notification(通知)
- 常见的对话框、通知栏Notification
- Android的各种通知Notification、Dialog、Toast、Snackbar
- android(44)(常见的对话框、通知Notification)
- Notification通知
- Notification通知
- Notification(通知)
- Notification通知
- Notification通知
- notification通知
- Android库so文件及skia函数的调用
- Ubuntu12.04 更新源
- Struts2 中文件的下载
- 算法上均匀分布的随机抽奖,如何避免现实的现场抽奖的中奖号码有时出现集中扎堆的现象?
- OS_FLAG.C
- 对话框通知(Dialog Notification)
- android Activity细节(二) Activity之间跳转细节
- RHEL NIS服务器搭建 (Master+Slave+Client)
- 订单状态审批流程
- Android四种Activity的加载模式
- Spring中AbstractCommandController控制器
- windows批处理(shell)多行字符串匹配
- 一些 NSArray 的基本操作代码例子
- MongoDB 学习 第三节 高级操作