RemoteViews 实现简单自定义通知栏
2016-04-05 16:58
204 查看
RemoteViews
作用:远程view,可跨进程更新界面。主要用于自定义通知栏及桌面小组件自定义通知栏:
Notification notification2 =new Notification(); notification2.icon=R.drawable.ic_launcher; notification2.tickerText="ticker"; notification2.when=System.currentTimeMillis(); notification2.flags=Notification.FLAG_AUTO_CANCEL; Intent it2=new Intent(this,ViewActivity.class); PendingIntent pt=PendingIntent.getActivity(getBaseContext(), 1, it2, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews remoteViews=new RemoteViews(getPackageName(),R.layout.item_notifiction); SimpleDateFormat dFormat=new SimpleDateFormat("yyyy-MM-dd,HH-mm-ss"); remoteViews.setTextViewText(R.id.txt, dFormat.format(System.currentTimeMillis())); remoteViews.setImageViewResource(R.id.img, R.drawable.ic_launcher); remoteViews.setImageViewResource(R.id.img2, R.drawable.ic_launcher); PendingIntent openActivity2pPendingIntent =PendingIntent.getActivity(getBaseContext(),0,it2,PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.img, openActivity2pPendingIntent); notification2.contentView=remoteViews; notification2.contentIntent=pt; NotificationManager nmManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nmManager.notify(2, notification2);
用法很简单,创建remoteView时只需提供 包名 及布局文件资源id即可
相关文章推荐
- gps定位
- 欢迎使用CSDN-markdown编辑器
- 负载均衡算法
- om.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException
- 周结 第六周
- 构建之法第四章读后感
- CodeForces 366B:Dima and To-do List【水】
- JSON格式
- lintcode:Subsets
- SQLite允许向一个integer型字段中插入字符串
- oracle For循环和触发器Tigger
- UIButton内文字自适应button长度
- 经典0-1背包基础注释
- SVN错误:Attempted to lock an already-locked dir
- array: 数组
- python接口测试(三)
- AndroidStudioSDK下tools下各个文件(夹)的用处
- idea maven jetty 配置
- 解决在低版本的xcode上使用高版本iOS系统手机进行真机测试
- Android View的 滑动冲突及工作流程