我一直在开发带有雪崩消息通知的应用程序,我遇到了一个问题,即在早于 Lollipop Android 版本的驱动设备上通知图标尺寸过大。
在 Lollipop 和 Marshmallow 设备上它看起来不错:
但是当我在我的 Android 4.4 模拟器上打开一个应用程序时,我发现了这个:
图像未缩放、未拟合,只是在中间裁剪。它看起来肯定不好。
NOTE: To make it clear, that this large notification icons is downloaded from server together with message date and content. It looks like this:
我的解决方案
在我的 avalanche 通知类中工作了几个小时后,我添加了两个方法,它们仅在检测到 Android pre-lollipop 版本时运行:
- 第一个将图标形状从矩形更改为正方形并添加白色背景
- 第二个将图标尺寸更改为 96x96
更改后,我在同一个 Kitkat 模拟器 (Moto X 2013) 上的通知图标看起来好多了:
问题
你能告诉我是否有更简单的方法来处理这个问题?如果不是,除了 96x96 之外,我还需要支持哪些图标尺寸?
提前致谢
最佳答案
如果我理解正确,您希望通知图标在 Lollipop 设备和 Lollipop 之前看起来都不错,根据我的经验,我为确保在两个 SDK 中都好看所做的是:
对于通知大图标,我使用这些尺寸的资源: 96x96(高清像素) 64x64(MDPI) 128x128 (xhdpi) 192x192(xxhdpi) 256x256 (xxxhdpi)
我使用这段代码来配置通知样式:
NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle(); notiStyle.setBigContentTitle(title); notiStyle.bigText(msg); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setContentTitle(title) .setContentText(msg) .setColor(coloresOnboarding.getColor()) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH) .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}) .setSmallIcon(R.mipmap.ic_launchersmall) .setAutoCancel(true) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcherlarge)) .setStyle(notiStyle); Intent resultIntent = new Intent(context, HeadAppMain.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int mId=1; mBuilder.setAutoCancel(true);
希望对你有帮助。
关于android - 通知 - 在 Lollipop Android 版本之前设置大图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34443265/