android中通知图标的颜色

Isj*_*Isj 2 notifications android push-notification android-drawable android-5.0-lollipop

有一次,当我在 Moto E 上升级到棒棒糖时,小通知图标变成了黑白(我读到它是新的谷歌指南)。所以好吧,我可以忍受它。现在我注意到图标又变了颜色,我没有改变我的代码并且一直在使用相同的可绘制对象。它肯定是黑白相间的,现在是彩色的。我的设备运行的是 Android 5.0.2 另外:

 compileSdkVersion 22
 buildToolsVersion "22.0.1"
 targetSdkVersion 22
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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

谁能告诉我这是怎么发生的?

Gáü*_*şhï 5

似乎自从 android 升级到 lolipop 以来,通知上的小图标只有黑色和白色……
但可以使用.setColor()以下代码所示的方法进行更改。

这是设置通知图标颜色的代码:-

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