当我在 Moto E 上升级到 lolipop 时,小通知图标变成了黑白(我读到这是新的谷歌指南)。所以好吧我可以忍受。 现在我注意到图标又变成了颜色,并且我没有更改我的代码并且一直在使用相同的可绘制对象。它确实显示的是黑白的,现在是彩色的。 我的设备是 Android 5.0.2 另外:
compileSdkVersion 22
buildToolsVersion "22.0.1"
targetSdkVersion 22
这是我的代码:
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);
谁能告诉我这是怎么发生的?
最佳答案
似乎自从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);
}
关于android - android中通知图标的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35118928/