我似乎不能让我的通知使用默认的通知背景颜色:它在应该是白色的地方保持灰色。同时,通知颜色在kitkat中是合适的。
我已经实施了这个问题的建议
我执行的内容似乎没有任何影响。values-v21的作用就好像它不存在一样。当然,我的目标sdk是21。我似乎就是找不到原因。
使用StartForeground
的服务显示通知。我也试过NotificationManager.notify()
,但没有什么区别。
此外,即使我只将包装器RelativeLayout留在xml:中,通知也是灰色的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
values-v21\styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NotificationText" parent="android:TextAppearance.Material.Notification" />
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title" />
<style name="NotificationTime" parent="android:TextAppearance.Material.Notification.Time" />
</resources>
尽管这些样式在其他地方没有使用(比如在我的应用程序主题声明中)。它们刚刚定义(在values-v21和values-v9中)。
我似乎无法使我的通知使用默认通知背景颜色:在应该是白色的地方,它仍然是灰色的。
没有。至少,不是棒棒糖。
如果在Notification.Builder
实例上设置Notification.MediaStyle
,则将使用深灰色背景(#ff424242
)(代替白色)
来自BaseStatusBar:
protected void applyColorsAndBackgrounds(StatusBarNotification sbn,
NotificationData.Entry entry) {
if (entry.expanded.getId() != com.android.internal.R.id.status_bar_latest_event_content) {
....
....
} else {
// Using platform templates
final int color = sbn.getNotification().color;
if (isMediaNotification(entry)) {
entry.row.setTintColor(color == Notification.COLOR_DEFAULT
? mContext.getResources().getColor(
R.color.notification_material_background_media_default_color)
: color);
}
}
....
}
isMediaNotification
检查您是否正在使用Notification.MediaStyle
。如果此检查通过,则会发生以下情况:
if (No color was set on Notification.Builder instance using `setColor()`) {
// R.color.notification_material_background_media_default_color
// is used as background
} else {
// The color you set is used instead.
}
R.color.notification_material_background_media_default_color
:
<color name="notification_material_background_media_default_color">#ff424242</color>
也许您可以通过截图通知并读取其背景的argb
值来确认这一点。如果问题是由MediaStyle
引入的,则颜色值将如上所述。更简单的方法是在Builder实例上使用setColor(int)
,看看这是否有什么不同。
这很可能是棒棒糖特异性的东西,因为MediaStyle
在<21.
<color name="notification_background_light">#fffafafa</color>
在Android 6(棉花糖)中为我匹配。
请参见:指南"灰色50"。
我遇到了同样的问题-我的通知颜色在棒棒糖上是黑色的,而所有其他通知都是系统颜色(白色)。我可以通过将targetSdkVersion更改为23 来修复它