Cannot use yellow with Android Nougat notification notification

I have a problem setting the small notification icon to yellow in Android 7.x

I am using notification.setColor(Color.YELLOW); when creating the notification object. It shows that the color of the olive (ish) instead of yellow.

Also tried using notification.setColor(Color.argb(255,255,255,0)); but no luck, he shows the same olive color (ish).

Here's what it looks like in Android 7.x

Android 7.1

Here's what it looks like in Android 6.x, which is the right color

Android 6.x

Both images display the same notification with the same code base, but use different Android devices.

I use PushWoosh to send / receive push notifications, below is the exact code that I use to create a notification object.

 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) { } } 
+5
source share
2 answers

Android provides minimal contrast between the foreground color and the background color.

With a yellow (# ffff35) foreground and white background, the contrast ratio is only 1.07: 1.

The olive foreground (# 717d13) has a minimum contrast ratio of 4.5: 1.

This is the corresponding patch in the Android device: https://android.googlesource.com/platform/frameworks/base.git/+/4ff3b120ff8a788e3afeb266d18caf072f0b8ffb%5E%21/

I calculated the above contrast ratios using http://webaim.org/resources/contrastchecker/ .

+5
source

Try to make sure that the user interface controls in the notification are also available in the Activity in your application, and you should always start Actions when users click on the notification. To do this, use the setContentIntent () method.

if you defined the color in colors.xml, then in the NotificationBuilder add the value as .setColor(getResources().getColor(R.color.<YOUR_COLOR>))

Source: NotificationCompat.Builder#setColor(int)

0
source

Source: https://habr.com/ru/post/1260555/


All Articles