棒棒糖通知背景颜色

时间:2015-02-06 10:08:25

标签: android notifications android-5.0-lollipop

我似乎无法使用默认通知背景颜色:它仍然是灰色的,应该是白色的。同时,通知颜色适用于kitkat。

我已在this question

中实施了建议

似乎对我实施的内容没有任何影响。值-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"/>

值-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>

虽然这些样式在其他任何地方都没有使用(比如在我的app主题声明中)。它们只是定义的(在值-v21和values-v9中)。

2 个答案:

答案 0 :(得分:4)

  

我似乎无法使用默认通知   背景颜色:它应该是白色的灰色。

没有。至少,不是在棒棒糖上。

如果您在#ff424242个实例上设置Notification.MediaStyle,则会使用深灰色背景(Notification.Builder)(代替白色):

来自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无法在&lt; 21。

答案 1 :(得分:0)

我遇到了同样的问题 - 我的通知颜色在Lollipop上是黑色的,而所有其他通知都是系统颜色(白色)。我可以通过将targetSdkVersion更改为23

来修复它
相关问题