android 实现自己定义状态栏通知(Status Notification)
在android项目的开发中,有时为了实现和用户更好的交互,在通知栏这一小小的旮旯里,我们通常须要将内容丰富起来,这个时候我们就须要去实现自己定义的通知栏,比如以下360或者网易的样式:
首先我们要了解的是 自己定义布局文件支持的控件类型:Notification的自己定义布局是RemoteViews,因此,它仅支持FrameLayout、LinearLayout、RelativeLayout三种布局控件,同一时候支持AnalogClock、Chronometer、Button、ImageButton、ImageView、ProgressBar、TextView、ViewFlipper、ListView、GridView、StackView和AdapterViewFlipper这些UI控件。对于其它不支持的控件,使用时将会抛出ClassNotFoundException异常。
同一时候呢我们还要了解的是Notification支持的Intent类型(都是PendingIntent类的实例)。
以下就是详细的实现了:在这个通知栏里 我们放一个进度条
//Get the notification manager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nm =
(NotificationManager)ctx.getSystemService(ns); //Create Notification Object
int icon = R.drawable.robot;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis(); Notification notification =
new Notification(icon, tickerText, when); //Set ContentView using setLatestEvenInfo
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, 0);
// notification.setLatestEventInfo(ctx, "title", "text", pi);// 使用默认的样式
notification.contentIntent = pi;
notification.contentView = new RemoteViews(ctx.getPackageName(),R.layout.noti);
//Send notification
nm.notify(1, notification);
实现的效果例如以下图:(右边为系统默认的样式)
这仅仅是一个简单的演示样例,为了实现我们自己的效果 我们仅仅须要改动布局文件就ok了。
android 实现自己定义状态栏通知(Status Notification)的更多相关文章
- 安卓状态栏通知Status Bar Notification
安卓系统通知用户三种方式: 1.Toast Notification 2.Dialog Notification 3.Status Bar Notification Status Bar Notifi ...
- android学习笔记---发送状态栏通知
发送消息的代码如下: //获取通知管理器 NotificationManager mNotificationManager = (NotificationManager) getSystemServi ...
- Material Design 之 定义状态栏(Status Bar)的颜色
Hey,好久不见.今天遇到一个问题,想要把Status Bar 和 Tool Bar的颜色弄成一样的,或者是类似的,例如Material Design: 图中Status Bar颜色比Tool Bar ...
- Android学习总结(十五) ———— Notification(状态栏通知)基本用法
一.Notification基本概念 Notification是一种具有全局效果的通知,它展示在屏幕的顶端,首先会表现为一个图标的形式,当用户向下滑动的时候,展示出通知具体的内容.我们在用手机的时候 ...
- 【Android】状态栏通知Notification、NotificationManager详解(转)
在Android系统中,发一个状态栏通知还是很方便的.下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置? 首先,发送一个状态栏通知必须用到两个类: NotificationMa ...
- Android 状态栏通知Notification、NotificationManager简介
Notification(通知)一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个通知: 在Android系统中, ...
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
- 状态栏通知Notification的简单使用
今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...
- Android应用开发学习之状态栏通知
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 状态栏通知涉及到两个类,一是Notification,它代表一个通知:另一个是NotificationManager ...
随机推荐
- POJ3071:Football(概率DP)
Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2 ...
- The 2013 South America/Brazil Regional Contest 题解
A: UVALive 6525 cid=61196#problem/A" style="color:blue; text-decoration:none">Atta ...
- PHP反射ReflectionClass、ReflectionMethod 入门教程
PHP反射ReflectionClass.ReflectionMethod 入门教程 作者:SNSGOU 发布于:2014-03-16 16:44:00 分类:PHP 浏览(6145) PHP5 ...
- Unity 3D 连接Mysql数据库
要想使用Unity直接连接数据库需要以下几个动态库
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
- winform —— 常用控件
1.textbox: 属性:text: 文本selectedtext: 获或设置选中文本canundo: 是否能够撤销 passwordchar:替换字符实现密码 ...
- sql server去除重复信息,
SELECT st_id FROM ( SELECT *,ROW_NUMBER() OVER( PARTITION BY st_code ORDER BY st_code ) AS num FROM ...
- [Linked List]Partition List
Total Accepted: 53879 Total Submissions: 190701 Difficulty: Medium Given a linked list and a value x ...
- Dom4j使用Xpath语法读取xml节点
我们可以使用Xpath的语法来轻易的读取xml的某个节点[类似于jQuery的选择器]: 使用Xpath语法需要添加新的jaxen-1.1-beta-7.rar 这个jar包 dom4j完整jar包我 ...
- CENTOS 挂载硬盘
查看物理卷:pvs 查看卷组:vgs 列出分区:lvs 查看磁盘:ll /dev/disk/by-path/ 扫描 LVM 找到 VG vgscan centos 下 mount: unknown f ...