NotificationCompat 4.1 SetSmallIcon and SetLargeIcon

后端 未结 5 1425
北海茫月
北海茫月 2020-12-14 00:24

I used this simple code to set a Notification in Android 4.1 or higher. It works well, but my problem comes with SmallIcon and LargeIcon. I understand that SmallIcon is show

相关标签:
5条回答
  • 2020-12-14 00:24

    I'd guess that this is the expected behavior.

    You should check to see that your small icon follows the UX guidelines for icon size. Small icons are limited to 24x24dp.

    The default behavior of an expanded notification is to show both the large icon and the small icon. I'm not sure that there's a way to get rid of the small icon, but why is this important?

    0 讨论(0)
  • 2020-12-14 00:26

    There is a way around this weird implementation. Instead of using setLargeIcon use this:

    Notification notification=notificationBuilder.build()
    notification.contentView.setImageViewResource(android.R.id.icon, R.drawable.your_large_icon);
    
    0 讨论(0)
  • 2020-12-14 00:35

    In my case, I just set my red icon as the large icon and the setColor to Color.WHITE and set a white icon as my small icon. That way, in the notifications area, my red icon is shown and the white icon is "disapeared".

    Bitmap icon = BitmapFactory.decodeResource(getResources(),R.drawable.app_logo);
    
    mBuilder.setContentIntent(resultPendingIntent).setColor(Color.WHITE).setLargeIcon(icon);
    
    0 讨论(0)
  • 2020-12-14 00:38

    In my case I had not placed icon image in all folders (xhdpi,hdpi,mdpi,ldpi).

    0 讨论(0)
  • 2020-12-14 00:39
    1. In my application I provide large (128x128 px) PNG drawable as small icon, and it shows scaled and without cropping. Is your drawable defined in bitmap file or maybe as XML resource? In XML you can specify several aspects of display (e.g. cropping). Double check your XML or use just PNG/JPG.

    2. As Android API documentation on Notification.setSmallIcon() clearly states:

      Set the small icon resource, which will be used to represent the notification in the status bar. The platform template for the expanded view will draw this icon in the left, unless a large icon has also been specified, in which case the small icon will be moved to the right-hand side.

    AFAIK there's no way you can override the behaviour, unless you provide your own notification template (via Notification.setContent()

    0 讨论(0)
提交回复
热议问题