Reputation: 13377
A non-custom notification built with android.support.v7.app.NotificationCompat.MediaStyle
can appear in very low contrast on Android Marshmallow. (It's fine on Lollipop and Nougat.)
Fig. 1. On Marshmallow, from outside the app, its pull-down notification has light text on a dark background:
Fig. 2. When the app's Activity is running, it switches to non-MediaStyle
to present alarm notifications without play/pause/stop controls, so they get the expected dark text on a light background:
Fig. 3. On Marshmallow, outside the app the heads-up notification has very low contrast:
--> That's hard to read!
Fig. 4. As an experiment, calling NotificationCompat.Builder#setColor(0xb71c1c)
does indeed set the non-MediaStyle
notification's accent color (compare with Fig. 2):
Fig. 5. ... and on Marshmallow, it sets the background color of MediaStyle
notifications:
which is too much color and no doubt out of spec.
Fig. 6. As a test workaround, the app could call setColor(0x9e9e9e)
(the standard accent color), which makes the heads-up notification more readable if out of spec:
Fig. 7. ... but it also makes the pull-down notification unusual and out of spec:
Fig. 8. ... and it looks worse in the large form:
Q. Is there a workaround to make the heads-up MediaStyle
notification more readable without messing up the pull-down MediaStyle
notification?
Obviously it'll be a Marshmallow-only workaround.
Edit: The bug is yet weirder. I tried to predict when it's likely to get a heads-up notification (that is, building a MediaStyle
notification with setSound()
) on Marshmallow, and call setColor()
only in that case. If the new notification replaces a pull-down notification of the same ID, it inherits the background color from that one! I.e. the previous pull-down notification's setColor()
sets this new heads-up notification's background color, while the later call to setColor()
sets its accent color. If the new notification doesn't replace a previous notification, then setColor()
sets both its background and accent colors.
Even when it succeeds at that, the notification stays colored when it reverts to a pull-down notification. So this approach doesn't work to even when it does correctly predict when the system will open a heads-up notification.
Summary: I'm seeking a workaround better than
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
builder.setColor(context.getColor(R.color.gray_text)); // #9e9e9e
}
in that it makes heads-up notifications more readable without risking making pull-down notifications hard to read or garish on any Marshmallow devices.
Upvotes: 4
Views: 1105
Reputation: 542
Things are even worse:
1.
I am using setSmallIcon() and setLargeIcon().
On Android 6 the small icon is only used in the menu bar, not in the notification itself. The notification uses the downscaled (in compact view) large icon which is displayed on the left side.
On Android 7 the large icon (downscaled in the compact view) is shown at the right side, well not the "right" side, but on the opposite of the left side, i.e. on the wrong side, to be precise. Further, the last line of the notification becomes the first one, which sabotages my use case. Further this line is preceded with the small icon and the app name; as a side effect the small line gets truncated which sabotages my app even more.
2.
On both Android versions setShowActionsInCompactView() did not have any visible effect.
3.
On lock screen the play/pause icon is visible (notification gets expanded), but not reachable without unlocking the device. So it's useless here.
Upvotes: 1
Reputation: 542
The problem does not only arise for "compat" notifications. Just adding this line:
builder.setStyle(new Notification.MediaStyle());
made my notification gray (with white text) in Android 6, while it remains white in Android 7. I do not have an Android 8 device for testing.
Note that I did not use some "compat" class here.
I suggest writing a bug report.
Upvotes: 1