【发布时间】:2019-05-16 08:18:43
【问题描述】:
我们是一个从事学校作业的小组。我们创建了一个自定义通知,它工作正常。唯一的问题是我很难弄清楚如何根据它是处于白天还是夜间模式来使自定义通知更改背景颜色。
我用于创建通知的代码
Intent challengedIntent = new Intent(this, StartActivity.class);
stackBuilder.addNextIntentWithParentStack(challengedIntent);
PendingIntent challengedPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.app_channel))
.setSmallIcon(R.mipmap.carfight_launcher)
.setCustomContentView(views)
.setCustomBigContentView(views)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setContentIntent(challengedPendingIntent)
.setColorized(true)
.setColor(Color.parseColor("#ff0000"));
views.setImageViewResource(R.id.imagesVeiw_wins,R.drawable.ic_medal_solid);
views.setImageViewResource(R.id.imageVeiw_matches,R.drawable.ic_battle);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, builder.build());
如何更改它以在日/夜模式下做出反应?
minSDKVersion 为 16
【问题讨论】: