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. lintcode204 单例

    单例   单例 是最为最常见的设计模式之一.对于任何时刻,如果某个类只存在且最多存在一个具体的实例,那么我们称这种设计模式为单例.例如,对于 class Mouse (不是动物的mouse哦),我们应 ...

  2. Java学习 · 初识 IO流

    IO流   1. 原理与概念 a)     流 i.           流动,流向 ii.           从一端移动到另一端 源头到目的地 iii.           抽象.动态概念,是一连 ...

  3. 给eclipse安装color-theme插件

    给eclipse安装color-theme插件 2016年03月22日 19:16:01 ming_love 阅读数:5193 标签: Eclipse Color Theme 更多 个人分类: jav ...

  4. leetcode9_C++判断一个整数是否是回文数

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 输出: true 示例 2: 输入: - 输出: false 解释: 从左向右读, 为 - ...

  5. LeetCode 145 ——二叉树的后序遍历

    1. 题目 2. 解答 2.1. 递归法 定义一个存放树中数据的向量 data,从根节点开始,如果节点不为空,那么 递归得到其左子树的数据向量 temp,将 temp 合并到 data 中去 递归得到 ...

  6. 【转载】图解Java常用数据结构(一)

    图解Java常用数据结构(一)  作者:大道方圆 原文:https://www.cnblogs.com/xdecode/p/9321848.html 最近在整理数据结构方面的知识, 系统化看了下Jav ...

  7. 卸载CDH5.7

    CDH5.7卸载1.记录用户数据目录2.关闭所有服务2.1在CM中,选择某个集群,然后停止集群.2.2逐个关闭CDH中的服务3.删除parcels4.删除集群5.卸载Cloudera manager ...

  8. [leetcode-662-Maximum Width of Binary Tree]

    Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...

  9. Greedy Gift Givers 贪婪的送礼者

    Description 对于一群要互送礼物的朋友,TRW要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人.然而,在任何一群 ...

  10. A+B 输入输出练习I

    while True: try: s=raw_input() a,b=s.split(' ') a,b=int(a),int(b) print a+b except EOFError: break A ...