Android notification icon color is not changed when background color is white

前端 未结 2 1943
醉梦人生
醉梦人生 2020-12-31 03:18

I upgraded android 6.0 and my app have problem.

when the status bar background color is not white, notification icon is good. (notification icon png has white and al

2条回答
  •  借酒劲吻你
    2020-12-31 04:13

    I think the problem lies in device android 5.0 or high.

    https://developer.android.com/design/patterns/notifications.html
    https://developer.android.com/about/versions/android-5.0-changes.html

    Here is a solution:

    Notification notification = new Notification.Builder(context)
            .setAutoCancel(true)
            .setContentTitle("My notification")
            .setContentText("Look, white in Lollipop, else color!")
            .setSmallIcon(getNotificationIcon())
            .build();
    
    return notification;
    

    and method getNotificationIcon():

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

提交回复
热议问题