简体   繁体   English

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

[英]Android Wear - use specified solid color for notification background

For some reason I can't make this simple concept work on Android wear. 出于某种原因,我无法让这个简单的概念适用于Android的佩戴。 I want the notification on Wear to have a solid color background with color of my choosing. 我希望Wear上的通知具有纯色背景和我选择的颜色。 This is what I'm trying to do: 这就是我想要做的:

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

As you can see, I'm setting the notification color to yellow. 如您所见,我将通知颜色设置为黄色。 And this does set the background on the notification to yellow on the phone. 这确实将通知背景设置为手机上的黄色。 But for some reason, background color on the notification I see on Android Wear is green. 但出于某种原因,我在Android Wear上看到的通知的背景颜色是绿色的。 Please see attached screenshots. 请参阅随附的屏幕截图。

在此输入图像描述

在此输入图像描述

I tried extending notification builder with a WearableExtender, but it doesn't have a "setColor"-like method, only "setBackground". 我尝试使用WearableExtender扩展通知构建器,但它没有类似“setColor”的方法,只有“setBackground”。 Why does Wear ignore specified notification color? 为什么Wear会忽略指定的通知颜色? And where does it take that green background color from? 它从哪里采取绿色背景颜色? How do I override that color? 如何覆盖该颜色?

Green background from your icon color. 从您的象颜色的绿色背景。

在此输入图像描述

You can call WearableExtender setBackground method 您可以调用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());

在此输入图像描述

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

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