java - 在通知图标中添加小图标

标签 java android notifications notification-icons

我正在使用下面的代码来获取通知图标。这会提供正常的通知图标,但右下角有一个小白框。我怎样才能为其设置图标。

 public void not() {
        Notification noti = new Notification.Builder(context).setSmallIcon(R.mipmap.lnc)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc))
                .setContentTitle("My Title")
                .setContentText("Done").setSmallIcon(R.mipmap.lnc)
                .build();
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // hide the notification after its selected
        noti.flags |= Notification.FLAG_AUTO_CANCEL;

        notificationManager.notify(0, noti);
    }

最佳答案

从Lollipop开始,你的小图标必须是单色的,即透明背景和白色,否则它将显示为白框。因此,将您的 R.mipmap.lnc 转换为剪影,即以这样的方式创建您的图标:您想要显示的部分应该是白色的,背景是透明的。如果您想向背景添加颜色,可以使用 setColor 方法来完成。

阅读this链接。

关于java - 在通知图标中添加小图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43187550/

相关文章:

java - 如何从一个 Activity 导航到另一个 Activity

android - 如何将一个简单的 Go 脚本作为 Android 服务运行?

php - 没有从php post请求中获取参数

iOS UILocalNotification 是操作按钮崩溃并损坏应用程序数据

java - Hibernate envers 自定义表

java - 如何获取@Pattern中属性文件的值

java - 在 adobe cq6 实例中使用放心框架运行单元测试用例

java - 如何在 Vaadin 上使用 withConverter 方法防止 Binder 中出现 “null” 文本

android - setColor小图标通知android

ios - 在 iOS9 上我无法设置在通知中心包含最近的 5 个项目,怎么办?