Why is my smallIcon for Notifications always greyed out?

后端 未结 3 1666
深忆病人
深忆病人 2020-11-30 03:55

I tried making the small icon exactly 16x16, gray-scaled, nothing but gray and white (the gray color being hex value 616161), to create a silhouette of my appli

3条回答
  •  一整个雨季
    2020-11-30 04:30

    For notification you have to use different icons for different versions of android:

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

    Get notification icon on the basis of version

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

提交回复
热议问题