【问题标题】:How to use different notification icon in Android for the notification area and the notification drawer如何在Android中为通知区域和通知抽屉使用不同的通知图标
【发布时间】:2017-12-02 06:40:51
【问题描述】:

我正在设置一个图标,使用白色透明背景中的 .png。 在锁定屏幕和通知区域显示时都可以正常工作。

图标以黄色突出显示: enter image description here

现在在通知抽屉中,图标也显示为白色(是同一个图标)。 enter image description here

但我想使用另一个图标,在本例中是蓝色的卡车。 现在我正在使用 Notification.Builder.SetColor() 将颜色设置为蓝色,并且标题以该颜色显示。

您可以看到 Gmail 图标在状态栏中显示为白色,在抽屉中显示为红色。

这是构建通知的实际代码。 代码适用于 Xamarin.Droid

var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;

Notification.Builder builder = new Notification.Builder(this)
                .SetContentTitle(title)
                .SetContentText(desc)
                .SetSmallIcon(Routes.Droid.Resource.Drawable.truck)
                .SetAutoCancel(true);
builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.truckColor));
builder.SetColor(Android.Graphics.Color.Rgb(33,150,243));

var notification = new Notification.BigTextStyle(builder).BigText(desc).Build();

notificationManager.Notify(-1, notification);

如何设置通知抽屉中的图标颜色,或使用不同的图标?

目标是在通知区域以白色显示图标,在通知抽屉中以蓝色显示。

【问题讨论】:

    标签: android xamarin colors notifications drawer


    【解决方案1】:

    图标颜色由 Android 7.0 (API 24) 自动设置。

    Android要给图标上色,需要根据不同的密度使用特定的资源,并添加到相应的目录中。

    在我的应用程序中,我将图标添加到

    /资源/drawable-hdpi

    /资源/drawable-xhdpi

    /资源/drawable-xxhdpi

    如果你和我一样,有一个图标的图像,你可以使用这个工具来创建新的资源:@​​987654321@

    源代码没有改变,但是当设置不同密度的图标时,图标在抽屉里是彩色的,在通知区域是白色的。

    以前我只是在 Resources/drawable 文件夹中使用默认的 .png 图标。 这会显示图标,但它始终以相同的颜色显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      相关资源
      最近更新 更多