Why is my smallIcon for notifications always grayed out?

I tried to make the small icon exactly 16x16, gray-scaled, nothing but gray and white (gray color hexvalue 616161), to create a silhouette of the icon of my application.

However, regardless of the fact that it only appears as a white / gray square in notifications. What am I doing wrong?

(My min apiis 21 if it matters)

+16
source share
3 answers

Follow this link

First, let's look at the Android documentation, which looks like this:

" , . - . , -. -. '

, , , , .

, , Android.

. , , . . .

enter image description here

: @Andrey Patseiko tool

+31

Android:

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

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;
}
+6

Android 5.0 API. Pl. .

( ) . , . , :

  • setColor(), .
  • Update or delete assets that include color. The system ignores all non-alpha channels in the action icons and in the main notification icon. You must assume that these icons will only be alpha. The system draws notification icons in white and action icons in dark gray.

So basically you should use silhouette icons as a notification icon for API level level 21+

+3
source

Source: https://habr.com/ru/post/1682288/


All Articles