Superman 69
Superman 69

Reputation: 69

Android notification large icon overlaid with blank small icon

The small icon on the top notification bar works perfectly. The large icon also appears. However, the bottom right corner of the large icon is overlaid with the small icon, which appears as a white over. Anyone has any idea? Thank you.

![private void showNotification(Context context, Intent intent) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);

    String title = intent.getExtras().getString("nTitle");
    String message = intent.getExtras().getString("nMessage");

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            context);

    Notification notification = mBuilder.setContentIntent(contentIntent)
            .setSmallIcon(R.drawable.android)
            .setColor(2)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.fuckya))
            .setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setContentText(message).build();

    mBuilder.setContentIntent(contentIntent);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    mBuilder.setAutoCancel(true);
    NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());

}][1]

enter image description here

Upvotes: 0

Views: 5877

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199805

Per the setColor() documentation"

Parameters

argb -The accent color to use

You are passing in 2, which is not a valid ARGB color, hence why the background color of your small icon does not appear correctly. Instead, choose a valid ARGB color.

If you have a color resource you'd like to use, you can use code such as

.setColor(context.getResources().getColor(R.color.notification_color))

In addition, note the Android 5.0 changes state:

Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

Your small icon should be entirely white and transparent - you can use tools such as the Notification Icon Generator to generate an appropriate icon.

Upvotes: 1

Related Questions