Android Wear - 如何为通知背景使用指定的纯色

5

由于某些原因,我无法在 Android Wear 上实现这个简单的概念。我希望 Wear 上的通知具有我选择的纯色背景。以下是我尝试完成此操作的代码:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder
            .setContentTitle("title")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("Text")
            .setColor(Color.YELLOW);

    Notification notification = builder.build();
    notificationManager.notify(123456, notification);

如您所见,我将通知颜色设置为黄色。这确实在手机上将通知的背景设置为黄色。但是由于某种原因,在Android Wear上看到的通知背景颜色是绿色的。请参见附加的截图。

enter image description here

enter image description here

我尝试使用WearableExtender扩展通知构建器,但它没有类似于“setColor”的方法,只有“setBackground”。为什么Wear会忽略指定的通知颜色?它从哪里获取那个绿色的背景颜色?我该如何覆盖那个颜色?

1个回答

10

将您的图标颜色设为绿色背景。

enter image description here

您可以调用WearableExtender的setBackground方法。

    int notificationId = 001;

    Bitmap bitmap = Bitmap.createBitmap(320,320, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.YELLOW);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("title")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("Text")
            .extend(new NotificationCompat.WearableExtender().setBackground(bitmap));

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(notificationId , builder.build());

这里输入图片描述


这个可以运行,但为什么要用320x320的纯色?1x1也可以,并且可以节省一些内存。 - Learn OpenGL ES

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接