美文网首页
[Android] 在5.0中的 Notification

[Android] 在5.0中的 Notification

作者: 希灵丶 | 来源:发表于2016-03-13 21:06 被阅读86次

关于 Notification 的用法可以在我的 Github 上找到: https://github.com/celesteshire/NotificationDemo

普通.gif 折叠.gif 悬挂.gif

下面来看看关于部分源码的解释

在 Notification 类的内部,还有一个 Builder 内部类,通过 Builder 类,能方便的构造 Notification

public Builder setWhen(long when) {  
  mWhen = when;  
  return this;  
}  

设置一个时间,在显示通知的时候会根据这个时间在通知栏进行排序。

public Builder setSmallIcon(int icon) {  
  mSmallIcon = icon;  
  return this;  
}  

设置小图标的方法

 public Builder setContentTitle(CharSequence title) {  
   mContentTitle = title;  
   return this;  
}  

设置标题栏文本

public Builder setContentText(CharSequence text) {  
  mContentText = text;  
  return this;  
}  

设置正文文本

public Builder setContentIntent(PendingIntent intent) {  
  mContentIntent = intent;  
  return this;  
}  

提供一个PendingIntent,在点击的时候会得到调用

public Builder setSound(Uri sound) {  
  mSound = sound;  
  mAudioStreamType = STREAM_DEFAULT;  
} 

设置提示音,传入一个音频的 Uri

public Builder setVibrate(long[] pattern) {  
  mVibrate = pattern;  
  return this;  
} 

设置震动

public Builder setAutoCancel(boolean autoCancel) {  
  setFlag(FLAG_AUTO_CANCEL, autoCancel);  
  return this;  
}  

设置是否自动取消

相关文章

网友评论

      本文标题:[Android] 在5.0中的 Notification

      本文链接:https://www.haomeiwen.com/subject/qrcflttx.html