简体   繁体   English

Android Wear通知出现意外的图标和背景颜色

[英]Unexpected Icon and background color for Android Wear notification

I am working on an app that sends notifications using the NotificationManager. 我正在使用使用NotificationManager发送通知的应用程序。 I set up an Android Wear emulator and have my android phone connected to the emulator. 我设置了一个Android Wear模拟器,并将我的android手机连接到了该模拟器。 The notifications my app generates appear on the Android Wear emulator, but the icons and color used are not what I'd expect. 我的应用程序生成的通知会显示在Android Wear模拟器上,但是使用的图标和颜色不是我所期望的。

The notification uses 1 of 3 icons as the notification icon, and sets a different LED color for each of the 3 cases. 该通知使用3个图标中的1个作为通知图标,并为3种情况中的每种情况设置不同的LED颜色。 The notification I see on the watch emulator uses the app icon, and not the icon I set in the notification. 我在手表模拟器上看到的通知使用的是应用程序图标,而不是我在通知中设置的图标。 Also, the background color of the notification is a solid red background, and I'm not sure what's setting it that color. 另外,通知的背景颜色是纯红色背景,因此我不确定将其设置为哪种颜色。

How can I get my notifications on the watch to match the icon of the notification I set, and how can I change the BG Color?! 如何在手表上获得与设置的通知图标匹配的通知,以及如何更改BG颜色?

Below, the Pink box is the application icon (and not the notification icon I'd expect). 在下面,粉红色框是应用程序图标(而不是我期望的通知图标)。

Watch Notification 观看通知

The notification icons come from the res/drawable folders of the handheld app. 通知图标来自手持式应用程序的res / drawable文件夹。 Do you have an icon with the same name in the res/drawable-hdpi folder? 在res / drawable-hdpi文件夹中是否有一个同名的图标?

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

Note: The bitmap that you use with setBackground() should have a resolution of 400x400 for non-scrolling backgrounds and 640x400 for backgrounds that support parallax scrolling. 注意:与setBackground()一起使用的位图对于非滚动背景应具有400x400的分辨率,对于支持视差滚动的背景应具有640x400的分辨率。 Place these bitmap images in the res/drawable-nodpi directory of your handheld app. 将这些位图图像放置在掌上电脑应用程序的res / drawable-nodpi目录中。 Place other non-bitmap resources for wearable notifications, such as those used with the setContentIcon() method, in the res/drawable-hdpi directory of your handheld app. 将其他可穿戴式通知的非位图资源(例如与setContentIcon()方法一起使用的那些资源)放置在手持式应用程序的res / drawable-hdpi目录中。

As far I know the colors of the LED are irrelevant for wearable notifications. 据我所知,LED的颜色与可穿戴式通知无关。 The background color is selected by default the icon and its priotity, if you set a big icon image it will use this. 默认情况下,背景颜色是图标及其优先级的选择,如果设置大图标图像,它将使用此颜色。 Since the quality of that big icon image meight be bad there is another call to achieve that. 由于大图标图像的质量可能很差,因此有另一个呼吁实现这一点。 Here is a full example: 这是一个完整的示例:

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

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

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