Android 棒棒糖通知
Android Lollipop notifications
如何在 Android 中使用 Lollipop 通知(用红色形状指出)做这样的事情:
以下是我实现通知的方式:
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_flight_takeoff_black_24dp)
.setContentTitle("Invitation")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setStyle(inboxStyle)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE
| Notification.DEFAULT_LIGHTS
)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
您可以通过设置Notification Actions向通知添加操作。
它允许您添加 PendingIntent
和与之一起显示的图像图标。
Notification.Action(int icon, CharSequence title, PendingIntent intent)
可以使用
设置图标
.setLargeIcon(R.drawable.large_icon)
.setSmallIcon(R.drawable.small_icon)
您可以使用 RootView 创建您的自定义通知(您想要的方式,例如大图标或小图标、文本视图位置等)。只需完成 this 教程。
如何在 Android 中使用 Lollipop 通知(用红色形状指出)做这样的事情:
以下是我实现通知的方式:
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
inboxStyle.addLine("jkl;adhjhasdkjhasdk");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_flight_takeoff_black_24dp)
.setContentTitle("Invitation")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setStyle(inboxStyle)
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE
| Notification.DEFAULT_LIGHTS
)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
您可以通过设置Notification Actions向通知添加操作。
它允许您添加 PendingIntent
和与之一起显示的图像图标。
Notification.Action(int icon, CharSequence title, PendingIntent intent)
可以使用
设置图标.setLargeIcon(R.drawable.large_icon)
.setSmallIcon(R.drawable.small_icon)
您可以使用 RootView 创建您的自定义通知(您想要的方式,例如大图标或小图标、文本视图位置等)。只需完成 this 教程。