1

I have such design of notification for the latest Android P enter image description here

For this notification I need to add blue user icon on the right hand. Could you tell me how to achieve this? Is it possible to make with one of the setter methods of NotificationBuilder? I need to write custom layout for this notification?

AlexF
  • 387
  • 1
  • 4
  • 20
  • 1
    While creating Notification there are two attributes: setSmallIcon(top left)and setLargeIcon(right). You can use the setLargeIcon to set the userIcon. – Surender Kumar Dec 06 '18 at 12:37
  • see this might help you https://stackoverflow.com/questions/41888161/how-to-create-a-custom-notification-layout-in-android – Bunny Dec 06 '18 at 12:39

2 Answers2

1

You have to use custom layouts for notification to override default configurations.

  1. Build a basic notification with NotificationCompat.Builder.
  2. Call setStyle(), passing it an instance of NotificationCompat.DecoratedMediaCustomViewStyle.
  3. Inflate your custom layout as an instance of RemoteViews.
  4. Call setCustomContentView() to set the layout for the collapsed notification.

Optionally, also call setCustomBigContentView() to set a different layout for the expanded notification.

Example:

// Get the layouts to use in the custom notification
RemoteViews notificationLayout = new RemoteViews(getPackageName(), 
R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), 
R.layout.notification_large);

// Apply the layouts to the notification
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
    .setSmallIcon(R.drawable.notification_icon)
    .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
    .setCustomContentView(notificationLayout)
    .setCustomBigContentView(notificationLayoutExpanded)
    .build();

Follow this for detailed info

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
0

On your builder add this line

.setLargeIcon(BitmapFactory.decodeResource(context.resources , R.drawable.your_image))
Jeremiah Polo
  • 641
  • 5
  • 10