簡體   English   中英

Android Wear - 使用指定的純色作為通知背景

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

出於某種原因,我無法讓這個簡單的概念適用於Android的佩戴。 我希望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上看到的通知的背景顏色是綠色的。 請參閱隨附的屏幕截圖。

在此輸入圖像描述

在此輸入圖像描述

我嘗試使用WearableExtender擴展通知構建器,但它沒有類似“setColor”的方法,只有“setBackground”。 為什么Wear會忽略指定的通知顏色? 它從哪里采取綠色背景顏色? 如何覆蓋該顏色?

從您的象顏色的綠色背景。

在此輸入圖像描述

您可以調用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