简体   繁体   English

Android中通知图标的颜色

[英]Color of Notification Icon in android

Sometime back when I upgraded to lolipop on my Moto E the small notification icon turned black and white(I read that its the new google guidline). 有时,当我在Moto E上升级到lolipop时,小通知图标变成了黑白(我读到它是新的Google指导原则)。 SO Ok I can live with it. 好吧,我可以忍受。 Now I have noticed that the icon has turned color again, and I havent changed my code and have been using the same drawable. 现在,我注意到该图标再次变色了,并且我没有更改代码并一直使用相同的drawable。 It sure was showing black and white and now its colored. 它肯定是显示黑白的,现在是彩色的。 My device is on Android 5.0.2 Also: 我的设备在Android 5.0.2上也:

 compileSdkVersion 22
 buildToolsVersion "22.0.1"
 targetSdkVersion 22

Here is my code: 这是我的代码:

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this)
            .setVibrate(new long[] { 10, 10, 10, 10, 10 })
                .setSound(alarmSound)
                .setSmallIcon(R.drawable.logo)
                .setContentTitle(title)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);

Can anybody tell me how this happened? 谁能告诉我这是怎么发生的?

It seems that ever since the android upgraded to lolipop the small icon on the notification comes in black and white only... 似乎自从android升级到lolipop以来,通知上的小图标就只有黑白...
but it can be changed with the .setColor() method as shown in the code below. 但是可以使用.setColor()方法更改它,如下面的代码所示。

Here's the code to set the color of the notification icon:- 这是设置通知图标颜色的代码:-

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder.setSmallIcon(R.drawable.appypie_small);
    notificationBuilder.setColor(getResources().getColor(R.color.notification_color));
} 
else {
    notificationBuilder.setSmallIcon(R.drawable.appypie_small);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM