0

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

Lena Bru
  • 13,521
  • 11
  • 61
  • 126
Lor Kam Hoi
  • 59
  • 1
  • 8

1 Answers1

1

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.

Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • I changed to .setColor(context.getResources().getColor(R.color.material_blue_grey_950)) but it's still the same – Lor Kam Hoi Jul 09 '15 at 06:24
  • Can you include a link to what your `R.drawable.android` looks like? – ianhanniballake Jul 09 '15 at 16:34
  • Hi again. I've found the solution, I downloaded stock icon from android-specific site https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.space.trim=1&source.space.pad=0&name=ic_stat_example and the white-over problem is solved. Somehow the previous small icons that i've used are 'not compatible' with the bitmapfactory-decoded large icon, I think. Thanks again! – Lor Kam Hoi Jul 10 '15 at 04:29
  • I've updated my answer with the issue - your small icons should be entirely white or transparent - color icons show up as solid white on Lollipop+ devices. – ianhanniballake Jul 10 '15 at 04:31
  • Ohh! You're da bomb! Thank you very much for your answer! – Lor Kam Hoi Jul 10 '15 at 05:20
  • Make sure to accept the answer if it helped you solve your problem. Good luck! – ianhanniballake Jul 10 '15 at 05:21