整个通知背景颜色



我看到一些应用程序在整个通知中显示背景色。

Myntra通知与背景色

使用BackgroundColor 的首次Cry通知

我尝试了这些链接的解决方案,但没有成功。

更改通知远程视图背景颜色https://cazimirroman.medium.com/android-how-to-set-the-background-color-for-a-notification-in-a-foreground-service-eaa505e2b82d

尝试使用DecoratedMediaCustomViewStyle->

val mediaSession = MediaSessionCompat(context,"tag")
mediaSession.setFlags(0)
mediaSession.setPlaybackState(PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_NONE,0,0f)
.build())
val builder = NotificationCompat.Builder(context, "channelId1")
.setSmallIcon(R.drawable.ic_notification_small)
.setContentTitle("The Title")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setAutoCancel(true)
.setColor(ContextCompat.getColor(context, R.color.pink))
.setColorized(true)
.setStyle(androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().setMediaSession(mediaSession.sessionToken))

在这种情况下,通知总是黑色的(假设是粉红色的(,也不会显示所有信息。

使用MediaStyle 的通知

您应该为您的通知创建两个自定义布局,一个用于折叠的通知,另一个用于扩展的通知,然后在您的活动中:

RemoteView collapsedRV = new RemoteViews (getPackageName(), R.layout.collapsed_notification)
RemoteView expandedRV = new RemoteViews (getPackageName(), R.layout.expanded_notification)

然后在你的构建器中,你需要设置这样的内容视图:

.setCustomContentView(collapsedRV)
.setCutomBigContentView(expandedRV)
.build()
notificationManager.notify(1,builder)

最新更新