Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在通知图标中添加小图标_Java_Android_Notifications_Notification Icons - Fatal编程技术网

Java 在通知图标中添加小图标

Java 在通知图标中添加小图标,java,android,notifications,notification-icons,Java,Android,Notifications,Notification Icons,我使用下面的代码来获取通知图标。这会给出正常的通知图标,但右下角有一个白色的小框。我如何设置图标也 public void not() { Notification noti = new Notification.Builder(context).setSmallIcon(R.mipmap.lnc) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipma

我使用下面的代码来获取通知图标。这会给出正常的通知图标,但右下角有一个白色的小框。我如何设置图标也

 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);
    }

从棒棒糖开始,您的小图标必须是单色的,即透明背景和白色,否则将显示为白色框。因此,将你的R.mipmap.lnc转换成一个轮廓,也就是说,创建你的图标时,你想要显示的部分应该是白色的,背景应该是透明的。如果要向背景添加颜色,可以使用setColor方法


阅读链接。

从棒棒糖开始,您的小图标必须是单色的,即透明背景和白色,否则它将显示为白色框。因此,将你的R.mipmap.lnc转换成一个轮廓,也就是说,创建你的图标时,你想要显示的部分应该是白色的,背景应该是透明的。如果要向背景添加颜色,可以使用setColor方法

阅读链接。

使用
setSmallIcon(R.drawable.YOUR_SMALL_ICON
)设置通知的小图标

仅供参考,根据设计指南,您必须为
Builder.setSmallIcon()
使用
轮廓。看

使用
setSmallIcon(R.drawable.YOUR_SMALL_图标
)设置通知的小图标

仅供参考,根据设计指南,您必须为
Builder.setSmallIcon()
使用
轮廓。看

试试这个


试试这个

这样我就有了一个主图标,然后它在右下角有一个圆圈,里面有一个白色的小框。Setcolor将圆形的颜色从默认的灰色设置为所选的颜色,尽管白色框保持白色。然后将不会有任何白色框,将有一个背景颜色设置的圆形&里面将是您创建的白色图标。是的,实际上我使用的是mipmap图标而不是drawable。现在我可以看到我的小图标了,我看到了一个主图标,然后在右下角有一个圆圈,里面有一个白色的小盒子。Setcolor将圆形的颜色从默认的灰色设置为所选的颜色,尽管白色框保持白色。然后将不会有任何白色框,将有一个背景颜色设置的圆形&里面将是您创建的白色图标。是的,实际上我使用的是mipmap图标而不是drawable。现在我可以看到我的小图标了。
Notification noti = new Notification.Builder(context)
            .setSmallIcon(getNotificationSmallIcon())
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc))
            .setContentTitle("My Title")
            .setContentText("Done")
            .build();

..................
..........................

private int getNotificationSmallIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
        NotificationCompat.Builder mNotifyBuilder;

 mNotifyBuilder = new NotificationCompat.Builder(context)
                .setContentTitle("Captian Mansoura")
                .setContentText("Busy , On trip Now")
             .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.lnc))

                .setSmallIcon(R.mipmap.notify_offline);