通知默认使用白色字体颜色(不可读)?
Notification uses white font color by default (unreadable)?
我已经实现了一个通知侦听器,基本上可以复制传入的 gmail 通知。然后我关闭 gmail 通知并显示我自己的(带有不同 text/action 按钮的轻微定制版本)。不过这不是自定义布局,我只是使用默认通知样式。
这在 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);
这是通知的样子
这是因为我使用的是旧的 SDK 吗? google 是否改变了这样做的方式?我不确定为什么会突然发生这种情况,因为我没有在此处创建自定义通知布局。这是我的 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()
}
}
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.
您应该针对 API 21 或更高版本以禁用此兼容性行为并在 API 21+ 设备上获得默认通知文本颜色。
确定使用下面的推送通知代码
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());
我已经实现了一个通知侦听器,基本上可以复制传入的 gmail 通知。然后我关闭 gmail 通知并显示我自己的(带有不同 text/action 按钮的轻微定制版本)。不过这不是自定义布局,我只是使用默认通知样式。
这在 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);
这是通知的样子
这是因为我使用的是旧的 SDK 吗? google 是否改变了这样做的方式?我不确定为什么会突然发生这种情况,因为我没有在此处创建自定义通知布局。这是我的 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()
}
}
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.
您应该针对 API 21 或更高版本以禁用此兼容性行为并在 API 21+ 设备上获得默认通知文本颜色。
确定使用下面的推送通知代码
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());