Android .setColor for Large Icon

8

I wanted to ask if there is a way to set the color of a notification with .setColor from .setLargeIcon ? Because as soon as I use both the .setSmallIcon and .setLargeIcon my color is used for the small Icon. I wanted to represent my individual notification icon with the LargeIcon and the app icon from which the notification was triggered with small Icon.

Example:

Bitmap maintenanceIcon = BitmapFactory.decodeResource(getResources(),R.drawable.maintenance);
            Intent replacePumpIntent = new Intent(this, FoodListActivity.class);
            PendingIntent replacePumpPendingIntent =  PendingIntent.getActivity(this,0,replacePumpIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationCompat.Builder maintenanceBuilder = new NotificationCompat.Builder(this)


                    .setLargeIcon(maintenanceIcon)
                    .setSmallIcon(R.drawable.app)
                    .setContentTitle("Maintenance: ")
                    .setColor(getResources().getColor(R.color.alertMaintenance))
                    .setContentText(Html.fromHtml(getString(R.string.alert_maintenance_message)))

                    .setLights(Color.YELLOW, 500 , 500)
                    .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
                    .setPriority(0x00000001)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(Html.fromHtml(getString(R.string.alert_maintenance_message))))
                    .addAction(R.drawable.ic_arrow_right_black, getString(R.string.alert_maintenance_button_1),replacePumpPendingIntent );

            NotificationManager maintenanceNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            maintenanceNotificationManager.notify(3, maintenanceBuilder.build());
java
android
notifications
icons
android-5.0-lollipop
asked on Stack Overflow Nov 18, 2014 by BinaryIT

3 Answers

2

According to this: https://stackoverflow.com/a/27023679/327011

There is no way to change the Large Icon background when having both. The large icon should not be a transparent.

answered on Stack Overflow Dec 12, 2014 by neteinstein • edited May 23, 2017 by Community
2

this will help you to remove grey color from the notification icon

 Notification notification = new NotificationCompat.Builder(context)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentText("Simple description of something meaningful")
    .setContentTitle("Yo check this out")
    .setColor(context.getResources()
            .getColor(R.color.brand_color))
    .build();

 NotificationManager manager  = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

 manager.notify(SINGLE_NOTIFICATION_ID, notification);

 brand_color is defined as #FF0066CC.

Source

answered on Stack Overflow Jul 5, 2015 by Adit Chauhan • edited Jul 5, 2015 by Yurets
0

You could tint large icon and then set to NotificationBuilder. Use this function to tint bitmap:

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)
            }
        )
    }

Then:

    NotificationCompat.Builder(context)
        .setColor(yourColor)
        .setLargeIcon(maintenanceIcon.tint(yourColor))
        .setSmallIcon(R.drawable.app)

In this case small and large icons will be tinted to desired color

answered on Stack Overflow Feb 3, 2021 by Oleksandr Albul

User contributions licensed under CC BY-SA 3.0