完全理解顶峰APP开发Android系列中的RemoteViews
完全理解顶峰APP开发Android系列中的RemoteViews
一、什么是RemoteViews
RemoteViews翻译过来就是远程视图.顾名思义,RemoteViews不是当前进程的View,是属于SystemServer进程.应用程序与RemoteViews之间依赖Binder实现了进程间通信.
二、RemoteViews的用法
RemoteViews使用最多的场合是通知栏和桌面小插件.以通知栏为例,讲解下它的用法.
1、新建一个Notification
这里要注意是在android3.0之前都是使用如下的形式构建一个Notification//1.新建一个Notification对象
NotificationmNotification=newNotification(;//2.添加属性,比如标题、内容、优先级、图片等mNotification.tickerText="这是通知栏的标题";mNotification.icon=R.drawable.ic_launcher;
mNotification.flags=Notification.FLAG_NO_CLEAR;
mNotification.setLatestEventInfo(this,"这是内容","这是标题",null;在3.0之后官方推荐使用建造者模式创建Notification.
NotificationmNotification=newNotification.Builder(this
.setContentTitle("这是标题".setContentText("这是内容"
.setSmallIcon(R.drawable.ic_launcher.build(;
Notification有很多属性,这里列举一些-setContentTitle设置标题-setContentText设置内容
-setLargeIcon设置通知栏大图标-setSmallIcon