androidnotificationsnotification-listener

Notification uses white font color by default (unreadable)?


I've implemented a notification listener that basically copies an incoming gmail notification. I then dismiss the gmail notification and show my own (slighlty customized version with different text/action buttons) instead. It's not a custom layout though, I'm just using the default notification style.

This worked great on Android KitKat (dark notification background style) but no longer works on Android Lollipop and above (light notification background style).

The title text and action buttons look fine, but the textcolor of the notification is white now (by default I guess) and no longer readable.

Here's how I implement it

    //Create New Notification Copy
            Notification.Builder ncomp = new Notification.Builder(this)
                    .setLargeIcon((Bitmap) extras.getParcelable(mNotification.EXTRA_LARGE_ICON))
                    .setContentInfo("" + numunread)
                    .setSubText(extras.getCharSequence(mNotification.EXTRA_SUB_TEXT))
                    .setContentText(extras.getCharSequence(mNotification.EXTRA_TEXT))
                    .setContentTitle(extras.getCharSequence(mNotification.EXTRA_TITLE))
                    .setSmallIcon(R.drawable.gmail)
                    .setLargeIcon(sbn.getNotification().largeIcon)
                    .setAutoCancel(true)
                    .setStyle(new Notification.BigTextStyle().bigText(extras.getCharSequence(mNotification.EXTRA_SUB_TEXT)));
    Notification noti = new Notification.BigTextStyle(ncomp)
                    .bigText(extras.getCharSequence(mNotification.EXTRA_TEXT))
                    .setSummaryText(extras.getCharSequence(mNotification.EXTRA_SUB_TEXT))
                    .setBigContentTitle(extras.getCharSequence(mNotification.EXTRA_TITLE_BIG))
                    .build(); 
    nManager.notify(oldNotificationTag, notifID, noti);

Here's what the notification looks like

Note how the text is there, but it's white and can't be seen.

Is this because of the old SDK I'm using? Did google change how this is done? I'm not sure why this is happening all of a sudden as I did NOT create a custom notification layout here. Here's my gradle file:

   android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 5
        versionName "1.22"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.0.0'
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.google.apis:google-api-services-gmail:v1-rev10-1.19.0'
    compile files('libs/asmack-android-8-0.8.9.jar')
    compile files('libs/mail.jar')
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile 'com.github.eluleci:flatui:0.1.2'
    compile 'de.cketti.library.changelog:ckchangelog:1.2.0'
   }

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Solution

  • As per the LOLLIPOP version code:

    Applications targeting this or a later release will get these new changes in behavior:

    • Notification.Builder will not have the colors of their various notification elements adjusted to better match the new material design look.

    You should target API 21 or higher to disable this compatibility behavior and get the default notification text colors on API 21+ devices.