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. 166. Nth to Last Node in List

    Description Find the nth to last element of a singly linked list. The minimum number of nodes in lis ...

  2. AngularJS 初探

    AngularJS,诞生于2009年,由Misko Hevery等人创建,后为Google所收购.这是一款优秀的前端JS框架,已经被用于Google的多款产品当中.AngularJS有着诸多特性,最为 ...

  3. Python基础 之 文件操作

    文件操作 一.路径 文件绝对路径:d:\python.txt 文件相对路径:在IDEA左边的文件夹中 二.编码方式 utf-8 gbk... 三.操作方式 1.只读 r 和 rb 绝对路径的打开操作 ...

  4. kvm网络虚拟化

    网络虚拟化是虚拟化技术中最复杂的部分,学习难度最大. 但因为网络是虚拟化中非常重要的资源,所以再硬的骨头也必须要把它啃下来. 为了让大家对虚拟化网络的复杂程度有一个直观的认识,请看下图 这是 Open ...

  5. 基础数据类型-list

    序列是python中的基础数据结构,序列里每一个元素都有一个下标,从0开始,依次递增. list,tuple,dictionary是使用最频繁的三类数据结构. (1)序列都有的方法包括:索引,切片,检 ...

  6. 软工时间-Alpha 冲刺 (2/10)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 学习了UI设计软件的使用,了解了项目开发的具体流程. 展示 ...

  7. iOS开发多线程编程2 - NSOperation

    1.简介 NSOperation实例封装了需要执行的操作和执行操作所需的数据,并且能够以并发或非并发的方式执行这个操作. NSOperation本身是抽象基类,因此必须使用它的子类,使用NSOpera ...

  8. <Effective C++>读书摘要--Implementations<二>

    <Item29> Strive for exception-safe code. 1.如下面的代码 class PrettyMenu { public: ... void changeBa ...

  9. Debian以及Ubuntu源设置

    在使用Debian和Ubuntu时,经常为了软件源烦恼,最近发现了一个网页,可以根据国家来设置源的地址,效果还不错. Debian:http://debgen.simplylinux.ch/ Ubun ...

  10. linux 环境变量配置(node)

    控制台 env 查看当前的环境变量配置 修改/etc/profile文件,在末尾添加以下内容 export NODE_HOME=/usr/local/node //Node所在路径 export PA ...