状态栏通知图标未更改 - API 23
Status bar notification icon not changing - API 23
我使用前台服务设置了持续通知。这是代码。
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this,"unique")
.setSmallIcon(R.drawable.ic_mms_black_24dp)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Notification notification= notificationBuilder.build();
startForeground(MY_ID,notification);
但是我在 setSmallIcon()
设置的图标没有效果,而是在状态栏和通知面板上显示默认应用程序图标 运行 在 Android 6. 但是之后我 运行 Android 5.1.1 (API LEVEL 22) 上面的代码显示了正确的图标。我尝试了不同类型的图标 (png,xml) 并且都运行良好。但是在我的 Marshmallow 上它只显示默认的应用程序图标。
如何找出原因?
来自Android 6(图标在最左角):
来自Android 5(图标在最左角):
编辑:我也试过白色图标。但通知仍然显示默认应用程序图标。图标有大小限制吗?但是 xml 图标是可以缩放的。
很有可能是因为你的图标是黑色的。
对于最新的 Android 版本,您需要通知图标为白色。
Status bar icons are composed simply of white pixels on a transparent
backdrop
您可以在此处查看指南 -
https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar
还要确保您拥有不同屏幕密度所需的所有正确尺寸。
问题似乎出在 OS 的制造过程中。 EMUI 4.0+ 存在不显示自定义通知图标的问题。它仅在状态栏中显示应用程序默认图标。如果您的型号有 EMUI 这是问题。本指南可能有助于解决问题 - How to enable ui tuner EMUI 4。
我使用前台服务设置了持续通知。这是代码。
NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this,"unique")
.setSmallIcon(R.drawable.ic_mms_black_24dp)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Notification notification= notificationBuilder.build();
startForeground(MY_ID,notification);
但是我在 setSmallIcon()
设置的图标没有效果,而是在状态栏和通知面板上显示默认应用程序图标 运行 在 Android 6. 但是之后我 运行 Android 5.1.1 (API LEVEL 22) 上面的代码显示了正确的图标。我尝试了不同类型的图标 (png,xml) 并且都运行良好。但是在我的 Marshmallow 上它只显示默认的应用程序图标。
如何找出原因?
来自Android 6(图标在最左角):
来自Android 5(图标在最左角):
编辑:我也试过白色图标。但通知仍然显示默认应用程序图标。图标有大小限制吗?但是 xml 图标是可以缩放的。
很有可能是因为你的图标是黑色的。
对于最新的 Android 版本,您需要通知图标为白色。
Status bar icons are composed simply of white pixels on a transparent backdrop
您可以在此处查看指南 - https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar
还要确保您拥有不同屏幕密度所需的所有正确尺寸。
问题似乎出在 OS 的制造过程中。 EMUI 4.0+ 存在不显示自定义通知图标的问题。它仅在状态栏中显示应用程序默认图标。如果您的型号有 EMUI 这是问题。本指南可能有助于解决问题 - How to enable ui tuner EMUI 4。