我在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) {
}
}