脚本宝典收集整理的这篇文章主要介绍了Android通知系统之Notification,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
##Notification
定义:
一种可以显示即时信息的控件,该控件显示在标题栏中,拉开后会看到通知的完整样式
样式:
1. 普通通知
- 使用普通通知必须的选项
三剑客
- 设置标题:setContentTITle()
- 设置图标:setSmallIcon()
- 添加描述:setContentText()
-
可选项
- setdefaults(系统默认闹铃|系统默认震动)
- setTicker(设置标题栏显示的内容。一般为contentText)
-
创建通知的步骤
- 定义NotificationComfat.Builder对象
- 设置必须选项和可选项
发布通知
NotifacationManager.notify(id,Notification)
-
象放入该对象中
2. 大视图通知
- 先创建一个简单通知
- 使用NotificationCompat.InboxStyle对象设置大视图通知的样式,
代码如下
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Event tracker")
.setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox style big view
inboxStyle.SetBigContentTitle("Event tracker details:");
...
// Moves events into the big view
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
// Moves the big view style object into the notification object.
mBuilder.setStyle(inBoxStyle);
3. 进度条通知
- 创建一个普通通知
- 开启一个线程,在改线程中使用setPRogress(进度条的最大值,当前进度值,false),在notify方法即时通知进度条,代码如下
mBuilder.setProgress(100,incr,false);
mNotifyManager.notify(0,mBuilder.build());
4. 自定义通知
以上是脚本宝典为你收集整理的Android通知系统之Notification全部内容,希望文章能够帮你解决Android通知系统之Notification所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。