【问题标题】:What is the right format of the icon in notification above lollipop?棒棒糖上方通知中图标的正确格式是什么?
【发布时间】:2020-06-16 07:41:49
【问题描述】:

我在我的应用程序中创建了提醒通知。因为我也在通知中使用了我的应用程序图标。但这并没有显示出来。而不是得到方形图标。搜索有关该问题,发现上面的棒棒糖发生这种情况。还找到了为上述棒棒糖创建图标的方法。将我的应用程序图标(png)转换为 svg 格式。这对我来说很好。我可以在我的应用通知中获得图标。但我真的很困惑,我所做的是否是正确的格式?如果不是最好的方法是什么。请任何机构给我一个适当的解释。

我知道设置小图标和大图标。我已将通知小图标设置为 svg 格式。这完美地显示在我的通知中...我想知道的是,在通知小图标中设置 svg 格式图标是正确的做法吗?

【问题讨论】:

    标签: android heads-up-notifications


    【解决方案1】:

    此代码适用于所有 android 版本:

    //    builder.setContentText(msg)
                //        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                //        .setVibrate(new long[]{500, 500})
                //        .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
                        .setSmallIcon(android.R.drawable.ic_menu_upload)
               //          .setOnlyAlertOnce(true)
               //          .setOngoing(false)
               //          .setPriority(NotificationCompat.PRIORITY_DEFAULT);
    

    【讨论】:

      【解决方案2】:

      如果你想制作大图标,试试这个。

       Bitmap icon2 = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
      
       NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
       bigText.bigText(textBody);
      
       notificationBuilder.setLargeIcon(icon2)
                          .setSmallIcon(R.mipmap.ic_launcher)
                          .setContentTitle(pushTitle)
                          .setContentText(contentText)
                          .setStyle(bigText)
                          .setLights(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), 3000, 3000)
                          .setVibrate(new long[]{500, 500, 500, 500})
                          .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                          .setAutoCancel(true)
                          .setPriority(NotificationCompat.PRIORITY_MAX)
                          .setContentIntent(pendingIntent);
      

      【讨论】:

      • @S T 我想知道setSmallIcon()里面icon的格式
      • 将 PNG 放入可绘制资源中以引用它们。 kitkat 设备中的 SVG 崩溃。
      • @S T 这就是我之前尝试过的。这样我就看不到我的图标了,而是看到了方形图标
      • 您必须从 setSmallIcon 使图标单色。那也是白的romannurik.github.io/AndroidAssetStudio/… 把图片放到上面的网站,结果画面出现在网站底部!如果你检查并放入就好了。请参考。
      • 我也发现了这个。 stackoverflow.com/a/29207365/10778405
      猜你喜欢
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 2015-08-12
      • 2015-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      相关资源
      最近更新 更多