繁体   English   中英

通知 - 在Lollipop Android版本上设置大图标

[英]Notification - set large icon on pre Lollipop Android version

我一直在使用雪崩消息通知处理应用程序,并且我遇到了比Lollipop Android版驱动设备更早的通知大图标大小的问题。

在Lollipop和Marshmallow设备上它看起来很好:

但是当我在Android 4.4模拟器上打开一个应用程序时,我发现了这个:

图像没有缩放,适合,只是在中间裁剪。 它看起来不太好。

注意:要明确说明,此大型通知图标将与消息日期和内容一起从服务器下载。 它看起来像这样:

我的解决方案

在我的雪崩通知课程中经过几个小时的工作后,我添加了两种方法,只有在检测到Android pre-lollipop版本时才会运行:

  • 第一个将图标形状从矩形更改为方形,并添加白色背景
  • 第二个将图标尺寸更改为96x96

更改后,我在同一Kitkat模拟器(Moto X 2013)上的通知图标看起来好多了:

你能否告诉我是否有更简单的方法来解决这个问题? 如果没有,除了96x96之外,我需要支持哪些图标尺寸?

提前致谢

如果我理解正确,你想让棒棒糖设备和棒棒糖前的通知图标看起来都很好,根据我的经验,我所做的就是确保两个SDK的外观都是这样的:

  1. 对于通知大图标我使用这些大小的资源:96x96(hdpi)64x64(mdpi)128x128(xhdpi)192x192(xxhdpi)256x256(xxxhdpi)

  2. 我使用此代码配置通知样式:

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

我希望这能帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM