Large notification icon background

后端 未结 2 1660
忘掉有多难
忘掉有多难 2020-12-13 04:37

Since Android 5.0 large icons in notifications have color background:

\"lollipop-notification\"

For sma

相关标签:
2条回答
  • 2020-12-13 05:10

    An large icon should always have a background (i.e. avatar). It's also used on wear devices as background for a notification. It's displayed on different background colors, therefore it should be a non-transparent picture.

    0 讨论(0)
  • 2020-12-13 05:14

    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.

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