通知默认使用白色字体颜色(不可读)?

时间:2017-02-14 03:29:54

标签: android notifications notification-listener

我已经实现了一个通知监听器,它基本上复制了传入的gmail通知。然后我解除了gmail通知并显示我自己的(带有不同文本/操作按钮的slighlty自定义版本)。它不是自定义布局,我只是使用默认通知样式。

这在Android KitKat(黑暗通知背景样式)上运行良好,但不再适用于Android Lollipop及以上版本(光通知背景样式)。

标题文本和操作按钮看起来很好,但通知的文本颜色现在是白色的(默认情况下我猜)并且不再可读。

这是我如何实现它

    //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);

以下是通知的内容

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

这是因为我正在使用的旧SDK吗?谷歌改变了这是怎么做的?我不知道为什么会突然发生这种情况,因为我没有在这里创建自定义通知布局。这是我的gradle文件:

   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()
    }
}

2 个答案:

答案 0 :(得分:4)

根据LOLLIPOP version code

  

针对此版本或更高版本的应用程序将在行为中获得以下新变化:

     
      
  • Notification.Builder不会调整各种通知元素的颜色,以便更好地匹配新材料设计外观。
  •   

您应该以API 21或更高版本为目标,以禁用此兼容性行为,并在API 21+设备上获取默认通知文本颜色。

答案 1 :(得分:-1)

确定使用下面的推送通知代码

Intent intent = new Intent(this, HomeMainActivity.class);
int id = (int) System.currentTimeMillis();
editor.putString("KEY_APPST", appst);
editor.apply();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("activity", title3);
intent.putExtra("id", tid);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int color = getResources().getColor(R.color.white);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
       .setSmallIcon(R.drawable.aquadeals_partner_tbgic32)
       .setContentTitle(title)
       .setSubText(title3)
       .setContentText(message)
       .setAutoCancel(true)
       .setTicker(title)
       .setDefaults(Notification.DEFAULT_LIGHTS)
      .setColor(color)
       .setStyle(new NotificationCompat.BigTextStyle().bigText(title))
       .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
       .setWhen(System.currentTimeMillis())
       .setLargeIcon(BitmapFactory.decodeResource(PushNotificationService.this.getResources(), R.drawable.appicon))
       .setSound(defaultSoundUri)
       .setContentIntent(pendingIntent);
NotificationManager notificationManager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id /* ID of notification */, notificationBuilder.build());