【问题标题】:Android Wear - use specified solid color for notification backgroundAndroid Wear - 使用指定的纯色作为通知背景
【发布时间】:2015-07-15 21:23:09
【问题描述】:

由于某种原因,我无法让这个简单的概念在 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 上看到的通知的背景颜色是绿色的。请参阅随附的屏幕截图。

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

【问题讨论】:

    标签: android android-notifications wear-os


    【解决方案1】:

    图标颜色的绿色背景。

    可以调用 Wea​​rableExtender 的 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 也可以,并且可以节省一些内存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多