Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android N notification title and icon color is darker

When showing a notification in android N and O it shows like this enter image description here

You can change the top color of the icon and the app name by using setColor method of the NotificationCompat.Builder, The problem is that the displayed color doesn't match the provided one as it gets darker in the notification.

I tested it on Google Pixel(Oreo). Is this documented somewhere? Any workarounds?

like image 985
Ahmed Hegazy Avatar asked Dec 01 '17 10:12

Ahmed Hegazy


People also ask

How do I change the notification color on my Android?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.


1 Answers

Google decided to restrict acceptable colors in Notification when using setColor. Yes, it's undocumented, unsolicited and evil! After some digging (hacker's way) it may be found in the source code of (internal) NotificationColorUtil. Inspect line 300 (findContrastColor) and 474 (resolveContrastColor) where the rationale is:

Resolves a Notification's color such that it has enough contrast to be used as the color for the Notification's action and header text.

I do not agree. Google should have known better and be doing no evil to the freedom of aesthetic choices of designers and developers.

like image 65
Nuno Henriques Avatar answered Sep 22 '22 08:09

Nuno Henriques