我在 Android 7.x 中将通知小图标设置为黄色时遇到问题
我在构建通知对象时使用 notification.setColor(Color.YELLOW);
。它显示橄榄色(有点)而不是黄色。
还尝试使用 notification.setColor(Color.argb(255,255,255,0));
但运气不好,它显示了相同的橄榄色。
这是它在 Android 7.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/