Currently the use of notifications in Android is still very common, in order to do version compatibility, commonly used Compatibility Pack Notificationcompat.builder and Notification.builder.
Recently found a problem on the Android5.0 device: The notification icon suddenly turns into a white square instead of the icon set in the code.
Cause of the problem
Read the developer documentation actually can also find some clues, although the author is directly check the source code found the cause of the problem. Http://developer.android.com/design/patterns/notifications.html the use distinct icons part of the article introduces several suggestions on the notice, Two of these are recommended behaviors that developers should not do.
Don ' Tplace any additional alpha (dimming or fading) into your small icons and action icons; They can has anti-aliased edges, but because Android uses these icons as masks (that's, only the alpha channel is used), The image should generally is drawn at full opacity. Don ' Tuse color to distinguish your apps from others. Notification icons should only is a white-on-transparent background image.
Simply put is 5.0 after Android official recommended do not add any additional transparency to the notification icon, gradient, do not attempt to use color to notify the icon with other applications, such as the system application, the app notification icon can only be on the transparent background of the white pattern.
As for the reason, the document does not elaborate, just mentioned 5.0 system will be in the bottom processing icon, want to know how to deal with the Android SDK API level 21 after the Notificaiton source code, which is written in more detail.
An example of a picture that is provided in conjunction with a document should be understandable.
If you do not follow the recommendations then there is a great chance that the above mentioned problems, why not do not make the problem?
This also depends on the code compiled version, according to the attempt, the current API 21 compile after the problem, 20 and the previous version of the compilation will not be a problem. So the simple solution to the problem is to compile the code with 20 and earlier versions. But to get a bottom-up solution, you still have to follow the documentation guidelines and the icons from the new design notification to meet the requirements.
SOURCE Analysis
Below to see what exactly 21 of the Android source code inside the action will cause the notification of the icons are all white.
Notification.java
Private remoteviews applystandardtemplate (int resid, boolean hasprogress) {//... if (mlargeicon != null) { Contentview.setimageviewbitmap (R.id.icon, mlargeicon); processlargelegacyicon (Mlargeicon, contentview); contentview.setimageviewresource (R.id.right_icon, msmallicon); contentview.setviewvisibility (r.id.right_icon, view.visible); processsmallrighticon (Msmallicon, contentview); } else { // small icon at left contentview.setimageviewresource (R.id.icon, msmallicon); contentview.seTviewvisibility (r.id.icon, view.visible); Processsmalliconaslarge (Msmallicon, contentview); } //...}
/** * Recolor small icons when used in the R.id.right_icon slot. */ private void processsmallrighticon (int smallicondrawableid, remoteviews contentview) { if (!islegacy () | | mcolorutil.isgrayscaleicon (Mcontext, smallicondrawableid)) { contentview.setdrawableparameters (R.id.right _icon, false, -1, 0xffffffff,          PORTERDUFF.MODE.SRC_ATOP, -1); contentview.setint (R.id.right_ icon, "Setbackgroundresource", R.DRAWABLE.NOTIFICATION_ICON_LEGACY_BG); contentview.setdrawableparameters ( r.id.right_icon, true, -1, resolvecolor (), PorterDuff.Mode.SRC_ATOP,                 -1); } }
Here I intercepted two more key code, after using Notificationcompat.builder to instantiate our notification, the final need to have a variety of icons, parameter configuration, applied to the notification view above. You can see that if we only set SmallIcon and do not set LargeIcon is also possible, at this time directly small as a large icon to the left of the ID of R.id.icon ImageView. Things to note in general, you can not set SmallIcon, otherwise the notification does not display properly.
The Processsmalliconaslarge method is responsible for handling our set of SmallIcon two times, that is, this will change the notification icon we finally see, including the top status bar and drop-down display of small icons.
Reference
-
Http://developer.android.com/design/patterns/notifications.html
-
Http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Small text
Source: http://www.cnblogs.com/avenwu/
Android5.0 Notice Change Analysis-recently found a problem on the Android5.1 device: The notification icon turns white