我正在创建图标,这样:
start = Icon.createWithResource(this, android.R.drawable.ic_media_play);
pause = Icon.createWithResource(this, android.R.drawable.ic_media_pause);
reset = Icon.createWithResource(this, android.R.drawable.ic_media_previous);
finish = Icon.createWithResource(this, R.drawable.ic_media_stop);
然后创建各种Notification.Action
实例:
public Notification.Action getStartAction() {
PendingIntent pendingIntent = getPendingIntent(NOTI_START_CLICKED);
return new Notification.Action.Builder(start, "Start", pendingIntent).build();
}
然后添加到Notification.Builder
:
Notification noti = getNotificationBuilder(time, description)
.addAction(getResetAction())
.addAction(getFinishAction())
.addAction(getStartAction())
.setStyle(new Notification.MediaStyle().
setShowActionsInCompactView(0, 1, 2))
.build();
notificationManager.notify(MEDITATION_NOTIFICATION_ID, noti);
finish
图标是我自己的,而其他图标都来自框架,所以我不明白为什么它们不那么清晰。它是由compileSdkVersion 27
Oreo构建的,并在运行8.1.0的Nexus 5X上运行。