Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large notification icon background

Tags:

Since Android 5.0 large icons in notifications have color background:

lollipop-notification

For small icon, it is the accent color of notification (Notification.Builder.setColor(int)). How do I set it for large icon? Is it part of the actual image? If it is, what should the circle radius be?

like image 869
Andrii Chernenko Avatar asked Nov 17 '14 13:11

Andrii Chernenko


People also ask

How do I make notification icons larger?

Navigate to Messages > New Push > Platform Settings > Google Android Options > Set the icon name without the file extension. With Large Notification Icons, you can also supply a URL where the icon will be displayed from.

How do I reduce icon size notification?

Select the gear icon to go to the system settings. Now go to the “Display” settings. Look for “Display Size” or “Screen Zoom.” Slide the dot on the scale at the bottom of the screen to adjust the size.


Video Answer


2 Answers

Yes, the color of the large icon is part of the actual image. The dimensions of the large icon on lollipop are 40x40dp with a optical view filling the entire image. So you should create an asset of 40x40dp with a circle of a 20dp radius. You can set the notification's large icon as follows:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)     .setSmallIcon(R.drawable.notification_small_icon)     .setLargeIcon(notificationLargeIconBitmap)     .setContentTitle("Notification")     .setContentText("Content text")     .setColor(context.getResources().getColor(R.color.accent_color)); 

If you need the large icon to be from a drawable resource you can get a Bitmap instance like this:

Bitmap notificationLargeIconBitmap = BitmapFactory.decodeResource(     context.getResources(),      R.drawable.notification_large_icon); 

If you want your notification to be displayed nicely with previous versions of android (kitkat and below), you should have a squared version of your large icon with a dimension of 64x64dp.

like image 60
alxscms Avatar answered Dec 23 '22 21:12

alxscms


You could use icon with transparent background as large icon for notification. Also you could tint large and small icons.
As already said use setColor() to tint small icon.
And for the large icon use this function:

fun Bitmap.tint(color: Int): Bitmap =     Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888).also { outBmp ->         Canvas(outBmp).drawBitmap(             this, 0f, 0f,             Paint().apply {                 this.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)             }         )     } 

So your code will look like this:

    NotificationCompat.Builder(context)         .setColor(yourColor)         .setLargeIcon(largeBitmap.tint(yourColor))         .setSmallIcon(R.drawable.small_icon) 

Here what you could get on Android 5.0: enter image description here On Android 10: enter image description here

like image 41
Oleksandr Albul Avatar answered Dec 23 '22 19:12

Oleksandr Albul