Why do icons set with Notification.Builder.setSmallIcon in Android Lollipop show as a white square?

前端 未结 8 2295
南旧
南旧 2020-12-23 18:54

I have this code:

Notification notif;

// Build notification
Notification.Builder notifBuilder = new Notification.Builder(context);
notifBuilder.setContentIn         


        
8条回答
  •  生来不讨喜
    2020-12-23 19:35

    Anyone still looking at this, the simplest way of getting your icon to display correctly is first rendering it with the Android Icon Studio here:

    https://romannurik.github.io/AndroidAssetStudio/icons-notification.html

    Unzip the files from the downloaded zip into your project /main folder, so they slot into the relevant drawable-xxxx folders.

    Then, to change colour in the notification use something like this:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_notification_appicon) // <-- Icon from Android Icon Studio 
        .setColor(context.getColor(R.color.holo_blue))    // <-- Set your preferred icon colour to appear in the notification dropdown list
        .setContentTitle("Title")
        .setContentText("Content")
        .setAutoCancel(true)
        .setCategory(NotificationCompat.CATEGORY_EVENT)
        .setDefaults(Notification.DEFAULT_ALL)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
    

提交回复
热议问题