【问题标题】:Unexpected Icon and background color for Android Wear notificationAndroid Wear 通知的意外图标和背景颜色
【发布时间】:2014-09-17 11:58:48
【问题描述】:

我正在开发一个使用 NotificationManager 发送通知的应用程序。我设置了一个 Android Wear 模拟器并将我的 android 手机连接到模拟器。我的应用生成的通知出现在 Android Wear 模拟器上,但使用的图标和颜色不是我所期望的。

通知使用 3 个图标中的 1 个作为通知图标,并为 3 个案例中的每一个设置不同的 LED 颜色。我在手表模拟器上看到的通知使用的是应用程序图标,而不是我在通知中设置的图标。此外,通知的背景颜色是纯红色背景,我不确定是什么设置了这种颜色。

如何让手表上的通知与我设置的通知图标相匹配,如何更改 BG 颜色?!

下面,粉色框是应用程序图标(而不是我期望的通知图标)。

Watch Notification

【问题讨论】:

    标签: android android-notifications wear-os


    【解决方案1】:

    通知图标来自手持应用程序的 res/drawable 文件夹。 res/drawable-hdpi 文件夹中有同名图标吗?

    http://developer.android.com/training/wearables/notifications/creating.html

    注意:与 setBackground() 一起使用的位图的分辨率应为 400x400(非滚动背景)和 640x400(支持视差滚动的背景)。将这些位图图像放在手持应用程序的 res/drawable-nodpi 目录中。将用于可穿戴通知的其他非位图资源(例如与 setContentIcon() 方法一起使用的资源)放在手持应用的 res/drawable-hdpi 目录中。

    【讨论】:

      【解决方案2】:

      据我所知,LED 的颜色与可穿戴通知无关。背景颜色默认选择图标及其优先级,如果您设置大图标图像,它将使用它。由于该大图标图像的质量可能很差,因此还有另一个要求来实现这一目标。这是一个完整的例子:

      NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
              .setContentTitle("title")
              .setContentText("message")
              // replace the drawable if you want something else
              .setSmallIcon(R.drawable.ic_launcher);
      
      NotificationCompat.WearableExtender extender =
                                          new NotificationCompat.WearableExtender();
      Bitmap bg = BitmapFactory.decodeResource(context.getResources(),
                                               R.drawable.background);
      // in the line above you can change the background image
      extender.setBackground(bg);
      builder.extend(extender);
      
      NotificationManagerCompat notificationManager =
                                NotificationManagerCompat.from(context);
      notificationManager.notify(42, builder.build());
      

      【讨论】:

      • 我不明白为什么手表上的通知图标是应用程序图标,而不是我用作手机上显示的通知图标的图标。
      猜你喜欢
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      • 2015-08-14
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多