1.通知

  Android 3.0以前使用的方法

             NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.dss,
"通知到了", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notification.setLatestEventInfo(this, "标题", "内容", contentIntent);
nm.notify(0, notification);

  替代方法

             Intent intent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("通知到了")
.setContentTitle("标题")
.setContentText("内容")
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.dss)
.setLargeIcon(
BitmapFactory.decodeResource(getResources(),
R.drawable.dss)).build();
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0, noti);

2.对话框

             AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("对话框标题");
builder.setMessage("对话框内容");
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(), "确定被点击了", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(), "确定被点击了", Toast.LENGTH_SHORT).show();
}
});
//禁止响应返回键
builder.setCancelable(false);
builder.create().show();

3.单选对话框

             AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请选择:");
final String[] items = {"喜欢", "不喜欢"};
builder.setSingleChoiceItems(items, 0, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//单击后退出单选对话框
dialog.dismiss();
}
});
builder.create().show();

4.多选对话框

             AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请选择你最爱吃的水果");
final String[] items={"苹果","梨","菠萝","香蕉","黄瓜"};
final boolean[] result =new boolean[]{true,false,true,false,false};
builder.setMultiChoiceItems(items, result, new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
//Toast.makeText(getApplicationContext(), items[which]+isChecked, 0).show();
result[which] = isChecked;
}
});
builder.setPositiveButton("提交", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
StringBuffer sb = new StringBuffer();
for(int i=0;i<result.length;i++){
//if(result[i]){
// sb.append(" " + items[i]);
//}
}
//Toast.makeText(getApplicationContext(), "您选中了"+sb.toString(), 0).show();
}
});
builder.show();//作用同 builder.create().show();

5.带进度条的对话框

             final ProgressDialog pd = new ProgressDialog(this);
pd.setTitle("警告");
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMax(100);
pd.setMessage("正在处理数据,请稍等。。。");
pd.show();
new Thread(){
public void run() {
for(int i = 0;i<100;i++){
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace();
}
pd.setProgress(i);
}
pd.dismiss();
};
}.start();

Android提示框与通知的使用的更多相关文章

  1. android提示框

    // 对话框 AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setMessage("是否确认删除 ...

  2. android标题栏上面弹出提示框(二) PopupWindow实现,带动画效果

    需求:上次用TextView写了一个从标题栏下面弹出的提示框.android标题栏下面弹出提示框(一) TextView实现,带动画效果,  总在找事情做的产品经理又提出了奇葩的需求.之前在通知栏显示 ...

  3. android标题栏下面弹出提示框(一) TextView实现,带动画效果

    产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...

  4. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  5. Android应用开发学习之Toast消息提示框

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1.  创建一个Toast对象.可 ...

  6. Cocos2d-x C++调用Android弹出提示框

    转载请注明地址,谢谢.. Cocos2d-x中提供了一个JniHelper类来让我们对Jni进行操作. (PS:弄了一天想自己写代码操作Jni的,但是总是出错,技术差不得不使用Cocos2d-x现成的 ...

  7. 如何实现android蓝牙开发 自动配对连接,并不弹出提示框

    之前做一个android版的蓝牙 与血压计通讯的项目,遇到最大的难题就是自动配对. 上网查资料说是用反射createBond()和setPin(),但测试时进行配对还是会出现提示,但配对是成功了 我就 ...

  8. Android 讲述Help提示框

    Android 讲述Help提示框 XML/HTML代码 <stringname="help_dialog_text"> <i>Author:fonter. ...

  9. Android消息提示框Toast

    Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...

随机推荐

  1. [Clr via C#读书笔记]Cp17委托

    Cp17委托 简单介绍 delegate回调函数机制,可以理解存储函数地址的变量类型: 类型安全: 引用类型支持逆变和协变: 回调 静态方法,实例方法 委托的本质 所有的委托都派生自System.Mu ...

  2. RNN概述-深度学习 -神经网络

    一 RNN概述    前面我们叙述了BP算法, CNN算法, 那么为什么还会有RNN呢?? 什么是RNN, 它到底有什么不同之处? RNN的主要应用领域有哪些呢?这些都是要讨论的问题. 1) BP算法 ...

  3. Netcore logging config

  4. 面试中要注意的 3 个 JavaScript 问题

    JavaScript 是 所有现代浏览器 的官方语言.因此,各种语言的开发者面试中都会遇到 JavaScript 问题. 本文不讲最新的 JavaScript 库,通用开发实践,或任何新的 ES6 函 ...

  5. Jamie and Alarm Snooze

    Description Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. Ho ...

  6. DAY7敏捷冲刺

    站立式会议 工作安排 (1)服务器配置 服务器端项目结构调整 (2)数据库配置 单词学习记录+用户信息 (3)客户端 客户端项目结构调整,代码功能分离 燃尽图 燃尽图有误,已重新修改,先贴卡片的界面, ...

  7. ACM 第十九天

    积性函数 积性函数线性筛,筛素数,u(n),欧拉函数: vis[]=vis[]=,mu[]=,phi[]=; ;i<=N;++i){ ,phi[i]=i-,prime[++cnt]=i; ,k= ...

  8. python学习笔记03:python的核心数据类型

    从根本上讲,Python是一种面向对象的语言.它的类模块支持多态,操作符重载和多重继承等高级概念,并且以Python特有的简洁的语法和类型,OOP十分易于使用.Python的语法简单,容易上手. Py ...

  9. lintcode-171-乱序字符串

    171-乱序字符串 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 注意事项 所有的字符串都只包 ...

  10. iOS开发改变字符串中指定字符颜色,大小等等

    NSString *strJTGZ = [NSString stringWithFormat:@"交通管制%d处 ",[jtgz intValue]]; NSMutableAttr ...