简体   繁体   中英

android - white circle notification icon in android 5

I've a problem with the notification icon in android .

this is my code :

Notification myNotification = new NotificationCompat.Builder(ctx)
                .setSmallIcon(getNotificationIcon())
                .setAutoCancel(false).setContentTitle(onvan)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
                .setContentIntent(pending).build();

        long number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
        notificationManager.notify((int) number, myNotification);


private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.ic_launcher : R.drawable.ic_launcher;
}

What is the problem ?

Post android Lollipop release android has changed the guidelines for displaying notification icons in the Notification bar. The official documentation says "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.” Now what that means in lay man terms is "Convert all parts of the image that you don't want to show to transparent pixels. All colors and non transparent pixels are displayed in white"

You can see how to do this in detail with screenshots here https://blog.clevertap.com/fixing-notification-icon-for-android-lollipop-and-above/

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM