Android自助餐之notification
2016-06-18 01:24
363 查看
通知栏各种玩法
通知栏各种玩法NotificationSample
SimpleNotificationDemo
CustomNotificationDemo
知识点
Notification
flag
default
NotificationManager
NotificationCompatBuilder
PendingIntent
RemoteViews
NotificationSample
网上各种玩法的demoSimpleNotificationDemo
简单的通知实现CustomNotificationDemo
自定义通知栏demo,实现自定义view与动态更新通知内容知识点
Notification
notification.bigContentView = view;这么做可以自定义通知的高度,但最大为200,最小为普通通知高度。如果使用builder的话,此处view与builder的一致。
flag
FLAG_AUTO_CANCEL用户点击时消失
FLAG_FOREGROUND_SERVICE表示正在运行一个服务
FLAG_INSISTENT通知铃声会重复响直到通知被取消或通知窗口被打开
FLAG_NO_CLEAR当用户点击清除所有时该通知不被清除
FLAG_ONGOING_EVENT该通知被正在运行的事件所引用(比如正在通话)
FLAG_ONLY_ALERT_ONCE该通知仅首次发送时震动或播放通知铃声,之前发送的该通知未取消的情况下
FLAG_SHOW_LIGHTS发送该通知时打开呼吸灯
default
DEFAULT_SOUND使用默认通知声音
DEFAULT_VIBRATE使用默认震动效果
DEFAULT_LIGHTS使用默认通知呼吸灯
DEFAULT_ALL全部使用默认
NotificationManager
NotificationCompat.Builder
setAutoCancel(boolean autoCancel)是否用户点击后消失
setContent(RemoteViews views)自定义通知的view
setContentInfo(CharSequence info)显示在右边的文本(时间下面)
setNumber(int number)显示在右边的数字(时间下面,如果调用了setContentInfo,则此设置不生效)
setContentIntent(PendingIntent intent)设置点击通知后的intent
setDeleteIntent(PendingIntent intent)设置用户直接移除该通知后的intent
setFullScreenIntent(PendingIntent intent, boolean highPriority)An intent to launch instead of posting the notification to the status bar
setLargeIcon(Bitmap icon)显示在通知栏的icon
setSmallIcon (int icon, int level)显示在通知栏的icon,尺寸较小
setContentTitle(CharSequence title)通知标题,icon的右边上部
setContentText(CharSequence text)通知文本,icon的右边下部
setLights(int argb, int onMs, int offMs)设置呼吸灯,依次为argb色值,亮起持续毫秒数,熄灭持续毫秒数
setOngoing(boolean ongoing)如果是正在进行中的通知,则不能被移除
setOnlyAlertOnce(boolean onlyAlertOnce)如果该通知正在显示,则再发通知不会触发铃声,震动,ticker
setPriority(int pri)优先级
setProgress(int max, int progress, boolean indeterminate)进度
setSound (Uri sound)通知铃声Uri,在默认音频流播放
setSound (Uri sound, int streamType)通知铃声Uri,在指定音频流播放
setStyle (NotificationCompat.Style style)设置通知样式
setSubText (CharSequence text)设置第三行文本(与progress冲突)
setTicker (CharSequence tickerText, RemoteViews views)发通知时在系统栏显示的文本和view
setTicker (CharSequence tickerText)发通知时在系统栏显示的文本
setUsesChronometer (boolean b)显示自动计时器
setVibrate (long[] pattern)设置震动效果
setWhen (long when)设置通知发送时间
addAction (int icon, CharSequence title, PendingIntent intent)在底部扩展一块位置显示这个按钮,最多三个
PendingIntent
对intent的包装pendingintent可以保存创建intent时的context,即使当时的context不存在了,也能从pendingintent里的context执行intent。
getActivity()封装打开一个activity的intent,就像
Context.startActivity()
getActivitys()封装打开一组activity的intent
getBroadcast()封装一个发广播的intent,就像
Context.sendBroadcast()
getService()封装一个开启服务的intent,就像
Context.startService()
RemoteViews
非UI线程从layout文件进行inflate:
new RemoteViews(packageName,R.layout.filename)
提供修改子view的简单方法:
remoteViews.setTextViewText(R.id.view_name, "string");
相关文章推荐
- Android内存泄漏(线程造成的内存泄漏与资源未关闭造成的内存泄漏)
- Android内存泄漏(非静态内部类创建静态实例造成的内存泄漏)
- Android自助餐之Jni(六)NDK入门
- Android内存泄漏(使用单例模式造成的内存泄漏)
- Android内存泄漏(Handler造成的内存泄漏(二))
- Android应用自动更新功能的代码实现
- [置顶] Android开发之常用框架WebView详解代码。超详细,送给初学者,完全掌握此控件
- 拍照 录像
- 详细介绍android回调机制及其使用
- Android Studio建立jni开发环境
- Android图片压缩学习
- Android之常用开发框架
- Android MediaPlayer工具类
- (OK)(OK)(All in CLI) running two Android-x86 which connect to NS3(MANETs) via "ethernet bridge"
- Android NDK开发篇:Java与原生代码通信(异常处理)
- Android NDK开发篇:Java与原生代码通信(数据操作)
- Android NDK开发篇(一):新版NDK环境搭建(免Cygwin,超级快)
- Android学习之消息框
- androidstudio下NDK正确姿势
- Android ADB命令大全(通过ADB命令查看wifi密码、MAC地址、设备信息、操作文件、查看文件、日志信息、卸载、启动和安装APK等)