棒棒糖通知背景色 [英] Lollipop notification background color
问题描述
我似乎无法使通知使用默认的通知背景颜色:它仍然是灰色,应该是白色.同时,通知颜色也适用于kitkat.
I can't seem to make my notification use default notification background color: it remains gray where it should be white. At the same time, notification colors are appropriate in kitkat.
我已在此问题中实现了建议
I have implemented suggestions in this question
对我实现的东西似乎没有任何影响.值-v21只是好像不存在一样. 自然,我的目标sdk是21.我似乎找不到原因.
There doesn't seem to be any effect on what I implement. The values-v21 simply acts as if it weren't there. Naturally, my target sdk is 21. I just can't seem to find the reason for this.
使用StartForeground
从服务中显示通知.我也尝试过NotificationManager.notify()
,但这没什么区别.
The notification is displayed from service using StartForeground
. I have also tried NotificationManager.notify()
, but it makes no difference.
此外,即使我只将包装器RelativeLayout保留在xml中,通知也是灰色的:
Also, the notification is gray even if I only leave the wrapper RelativeLayout in the 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:
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>
尽管这些样式未在其他任何地方使用(例如在我的应用程序主题声明中使用).它们是刚刚定义的(在值-v21和值-v9中).
Though these styles aren't used anywhere else (like in my app theme declaration). They are just defined (in values-v21 and values-v9).
推荐答案
我似乎无法使我的通知使用默认通知 背景颜色:在应该为白色的地方仍保持灰色.
I can't seem to make my notification use default notification background color: it remains gray where it should be white.
不.至少不是在棒棒糖上.
No. At least, not on Lollipop.
如果在Notification.Builder
实例上设置Notification.MediaStyle
,将使用深灰色背景(#ff424242
)(代替白色):
The darkish-gray background (#ff424242
) will be used (in place of white) if you set Notification.MediaStyle
on your Notification.Builder
instance:
来自 isMediaNotification
检查您是否正在使用Notification.MediaStyle
.如果此检查通过,则会发生以下情况:
isMediaNotification
checks if you are using Notification.MediaStyle
. The following takes place if this check comes through:
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)
,看看是否有区别.
Perhaps you can confirm this by taking a screenshot of your notification and reading the argb
value of its background. If the issue is introduced by MediaStyle
, the color value will be as above. Even simpler approach would be to use setColor(int)
on your Builder instance and see if that makes a difference.
这很可能是棒棒糖特有的,因为MediaStyle
在<上不可用. 21.
This could very well be a Lollipop-specific thing since MediaStyle
isn't available on < 21.
这篇关于棒棒糖通知背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!