2

Surprising my APP's icon comes up with white color icon in notification bar on my Nexus 5. This is only in Nexus 5.

enter image description here

There is a question already about this the answer shows I need have: target 20. Which I have tried already: Like below no difference.

defaultConfig 
{
    applicationId "com.cn.redquest"
    minSdkVersion 20
    targetSdkVersion 20
    versionCode 10
    versionName "1.00"
} 

Can somebody help me fix this?

Let me know!

Thanks!

TheDevMan
  • 5,914
  • 12
  • 74
  • 144

1 Answers1

1

Setting the target SDK to 20 means that you do not build your app for Android Lollipop. This will make your notification icon display all colors, but is not a long-term solution, since you will want to build for Lollipop (at least eventually).

At http://developer.android.com/design/style/iconography.html you can read about that the white style is how notifications are meant to be displayed in Lollipop (SDK 21). Google also suggests using a custom bg color - https://developer.android.com/about/versions/android-5.0-changes.html

I think a better solution is to actually provide the system with a silhouette icon, if the device is running Android Lollipop.

For instance:

Notification notification = new Notification.Builder(context)
   .setAutoCancel(true)
   .setContentTitle("My notification")
   .setContentText("Look, white in Lollipop, else color!")
   .setSmallIcon(getNotificationIcon())
   .build();

And, in the getNotificationIcon method:

private int getNotificationIcon() {
    boolean useSilhouette = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
    return useSilhouette ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
Daniel Saidi
  • 6,079
  • 4
  • 27
  • 29
  • Hey! what is R.drawable.ic_silhouette here? – Sanjana Nair Jun 19 '15 at 09:21
  • 2
    The last line is a check, where a silhouette image is returned for Android Lollipop or later. For older Android versions, the launcher icon is returned. R.drawable.ic_silhouette is thus a possible image resource in your project. You can return any image there...but it should be an image that works with a single color. – Daniel Saidi Jun 23 '15 at 07:30