【问题标题】:Icon not displaying in notification: white square shown instead and display it using mipmap launcher通知中未显示图标:改为显示白色方块并使用 mipmap 启动器显示它
【发布时间】:2017-02-21 16:03:36
【问题描述】:

// 3. 创建并发送通知 通知通知 = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher)

            .setContentTitle("Geofence Monitor")

            .setContentText(text)
            .setContentIntent(pendingNotificationIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true)
            .build();
    notificationManager.notify(0, notification);
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {


        new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher);
    } else {
        new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher);
    }

}

}

我的问题是,当我运行应用程序时,设备上的应用程序支持 mipmap 启动器,但在 lolipop 及以上设备中不显示白色,我想在 lolipop 及以上设备中显示相同的 mipmap 启动器。 提前感谢和帮助!

【问题讨论】:

    标签: java android


    【解决方案1】:

    您必须为不同的可绘制文件夹保持适当的大小。

    试试这些建议的尺寸: 32 × 32 (mdpi) 中的 24 × 24 区域 48 × 48 (hdpi) 中的 36 × 36 区域 64 × 64 (xhdpi) 中的 48 × 48 区域 96 × 96 (xxhdpi) 中的 72 × 72 区域 128×128(xxxhdpi)中的96×96区域

    并尝试遵循这些准则here

    【讨论】: