Android Notification gray square on MIUI devices

48 Views Asked by At

On MIUI devices, there is an option to choose the notification style between Android and MIUI. When I select android style, my icon is displayed as a gray square, and when MIUI style is displayed, the icon is displayed correctly. I noticed that the Gmail icon changes its display depending on the selected style.

Android Style:

Android Style

MIUI STYLE:

MIUI Style

When I chose the android style, my icon looks like this:

My Icon

When I chose MIUI style, my icon is displayed correctly with all colors.

At the moment, I'm setting the icon like this:

val icon = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
    R.mipmap.ic_launcher else R.drawable.ic_app_icon
notificationBuilder.setSmallIcon(icon)

How do I set an icon to achieve the same result as gmail? Maybe I need to make some special icon?

1

There are 1 best solutions below

0
dev_nil On

Solution:

notificationBuilder.setSmallIcon(R.drawable.miui_style, 2) // It will be displayed when MIUI style is selected
notificationBuilder.setSmallIcon(R.drawable.android_style_icon,1)// It will be displayed when ANDROID style is selected

Use Builder setSmallIcon(int icon, int level) to set the icon level