棒棒糖通知背景色

vel*_*lis 2 notifications android android-5.0-lollipop

我似乎无法使通知使用默认的通知背景颜色:它在应该为白色的地方仍保持灰色。同时,通知颜色适用于kitkat。

我已经在这个问题上实施了建议

似乎对我实施的内容没有任何影响。值-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"/>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

尽管这些样式并未在其他任何地方使用(例如在我的应用主题声明中)。它们是刚刚定义的(在值-v21和值-v9中)。

Vik*_*ram 5

我似乎无法使通知使用默认的通知背景颜色:它在应该为白色的地方仍保持灰色。

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

#ff424242如果您Notification.MediaStyleNotification.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);
        }
    }
 ....
}
Run Code Online (Sandbox Code Playgroud)

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.
}
Run Code Online (Sandbox Code Playgroud)

R.color.notification_material_background_media_default_color

<color name="notification_material_background_media_default_color">#ff424242</color>
Run Code Online (Sandbox Code Playgroud)

也许您可以通过截取通知的屏幕截图并阅读argb其背景值来确认这一点。如果问题是由引入的MediaStyle,则颜色值将如上所述。甚至更简单的方法是setColor(int)在您的Builder实例上使用,看看是否有所作为。

这很可能是棒棒糖特有的东西,因为MediaStyle在<21上不可用。

  • 问题在于,该特定通知是由service.startForeground()设置的。这会自动将其放置在服务图标之间,并且稍后会放置任何“正常”通知。所以不,这没有帮助。 (2认同)