android - Android Nougat 通知的小图标不能使用黄色

标签 android notifications google-cloud-messaging

我在 Android 7.x 中将通知小图标设置为黄色时遇到问题

我在构建通知对象时使用 notification.setColor(Color.YELLOW);。它显示橄榄色(有点)而不是黄色。

还尝试使用 notification.setColor(Color.argb(255,255,255,0)); 但运气不好,它显示了相同的橄榄色。

这是它在 Android 7.x 中的样子

Android 7.1

这是它在 Android 6.x 中的样子,这是正确的颜色

Android 6.x

两张图片使用相同的代码库显示相同的通知,但使用不同的 Android 设备。

我正在使用 PushWoosh 发送/接收推送通知,下面是我用来创建通知对象的确切代码。

public class NotificationFactory extends AbsNotificationFactory {
@Override
public Notification onGenerateNotification(PushData pushData) {
    PushwooshUserdata pushwooshUserdata = GsonUtil.fromJson(pushData.getExtras().getString("u"), PushwooshUserdata.class);

    //create notification builder
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext());
    notificationBuilder.setContentTitle("Header");
    notificationBuilder.setContentText("Message");

    //set small icon (usually app icon)
    notificationBuilder.setSmallIcon(R.drawable.notification_icon);
    notificationBuilder.setColor(Color.argb(255,255,255,0));

    //set ticket text
    notificationBuilder.setTicker(getContentFromHtml(pushData.getTicker()));

    //display notification now
    notificationBuilder.setWhen(System.currentTimeMillis());

    //build the notification
    final Notification notification = notificationBuilder.build();

    //add sound
    addSound(notification, pushData.getSound());

    //add vibration
    addVibration(notification, pushData.getVibration());

    //make it cancelable
    addCancel(notification);

    //all done!
    return notification;
}

@Override
public void onPushReceived(PushData pushData) {
}

@Override
public void onPushHandle(Activity activity) {
}
}

最佳答案

Android 正在确保前景颜色和背景颜色之间的最小对比度。

黄色 (#ffff35) 前景和白色背景,对比度仅为 1.07:1。

橄榄前景 (#717d13) 的最小对比度为 4.5:1。

这是Android源中的相关补丁:https://android.googlesource.com/platform/frameworks/base.git/+/4ff3b120ff8a788e3afeb266d18caf072f0b8ffb%5E%21/

我使用 http://webaim.org/resources/contrastchecker/ 计算了上述对比度.

关于android - Android Nougat 通知的小图标不能使用黄色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40877715/

相关文章:

android - 在 Android Gingerbread 上通过蓝牙传输大量数据

android - 值等于dimens.xml 中的match_parent 和fill_parent?

android - 用户通过滑动删除华为设备后在前台重新启动通知(如 Strava/Endomondo)

ios - 如果您在桌面上阅读过,Facebook Messenger 如何从锁定屏幕清除推送通知?

android - 在 xamarin 中关闭应用程序时接收推送通知

java - 服务器端 GCM 返回错误 400

android - android 可以在 GCM 和 C2DM 上工作吗?

java - 如何在Android 2.1+实现圆角标签

android - 如何导出点云数据(Project Tango)?

android - App关闭时不触发AlarmManager