1

I'm seeing some apps showing background color in whole notification.

Myntra Notification with BackgroundColor

First Cry Notification with BackgroundColor

I tried solutions from these links but nothing worked.

Changing Notification RemoteViews Background Color https://cazimirroman.medium.com/android-how-to-set-the-background-color-for-a-notification-in-a-foreground-service-eaa505e2b82d

Tried using 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))

In this case notification is coming black always (suppose to be pink) and also doesn't show all the information.

Notification using MediaStyle

Afsar
  • 23
  • 6

1 Answers1

-1

You should create two custom layouts for your notifications, one for a collapsed notification and one for an expanded notification, then in your activity:

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

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

then in your builder you need to set the content view like this:

.setCustomContentView(collapsedRV)
.setCutomBigContentView(expandedRV)
.build()

notificationManager.notify(1,builder)
UnBanned
  • 121
  • 11