简体   繁体   中英

Android Wear - use specified solid color for notification background

For some reason I can't make this simple concept work on Android wear. I want the notification on Wear to have a solid color background with color of my choosing. 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. Please see attached screenshots.

在此输入图像描述

在此输入图像描述

I tried extending notification builder with a WearableExtender, but it doesn't have a "setColor"-like method, only "setBackground". Why does Wear ignore specified notification color? 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

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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