【问题标题】:Notification - set large icon on pre Lollipop Android version通知 - 在 Lollipop Android 版本上设置大图标
【发布时间】:2015-12-23 20:32:10
【问题描述】:

我已经在开发带有雪崩消息通知的应用程序,但在比 Lollipop Android 版本驱动的设备上,我遇到了通知大图标大小的问题。

在 Lollipop 和 Marshmallow 设备上看起来不错:

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

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

注意:为了清楚起见,这个大通知图标是 从服务器下载消息日期和内容。它 看起来像这样:

我的解决方案

在我的雪崩通知类工作了几个小时后,我添加了两个方法,它们仅在检测到 Android 棒棒糖前版本时运行:

  • 第一个将图标形状从rectangle更改为square并添加white背景
  • 第二个将图标尺寸更改为 96x96

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

问题

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

提前致谢

【问题讨论】:

    标签: android android-layout notifications android-notifications


    【解决方案1】:

    如果我理解正确,您希望通知图标在棒棒糖设备和棒棒糖前都看起来不错,根据我的经验,我为确保两个 SDK 的良好外观所做的工作是这样的:

    1. 对于通知大图标,我使用以下大小的资源: 96x96 (高清) 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);
      

    我希望这对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-01
      • 2015-10-24
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      相关资源
      最近更新 更多