Lollipop notification background color

ぃ、小莉子 提交于 2019-12-06 08:51:28

I can't seem to make my notification use default notification background color: it remains gray where it should be white.

No. At least, not on Lollipop.

The darkish-gray background (#ff424242) will be used (in place of white) if you set Notification.MediaStyle on your Notification.Builder instance:

From BaseStatusBar:

protected void applyColorsAndBackgrounds(StatusBarNotification sbn,
        NotificationData.Entry entry) {

    if (entry.expanded.getId() != com.android.internal.R.id.status_bar_latest_event_content) {
        ....
        ....
    } else {
        // Using platform templates
        final int color = sbn.getNotification().color;
        if (isMediaNotification(entry)) {
            entry.row.setTintColor(color == Notification.COLOR_DEFAULT
                    ? mContext.getResources().getColor(
                            R.color.notification_material_background_media_default_color)
                    : color);
        }
    }
 ....
}

isMediaNotification checks if you are using Notification.MediaStyle. The following takes place if this check comes through:

if (No color was set on Notification.Builder instance using `setColor()`) {
    // R.color.notification_material_background_media_default_color 
    // is used as background
} else {
    // The color you set is used instead.
}

R.color.notification_material_background_media_default_color:

<color name="notification_material_background_media_default_color">#ff424242</color>

Perhaps you can confirm this by taking a screenshot of your notification and reading the argb value of its background. If the issue is introduced by MediaStyle, the color value will be as above. Even simpler approach would be to use setColor(int) on your Builder instance and see if that makes a difference.

This could very well be a Lollipop-specific thing since MediaStyle isn't available on < 21.

<color name="notification_background_light">#fffafafa</color>

matched for me in Android 6 (Marshmallow).

See: Guide lines "Grey 50".

I had the same problem - my notification color was black on Lollipop while all other notifications were of system color (white). I could fix it by changing targetSdkVersion to 23

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!