android中通知图标的颜色

时间:2016-01-31 20:14:57

标签: android notifications push-notification android-5.0-lollipop android-drawable

有时我在我的Moto E上升级到lolipop时,小的通知图标变成黑白(我读到它是新的google guidline)。好的,我可以忍受它。 现在我注意到图标再次变色,我没有更改我的代码,并且一直使用相同的drawable。它肯定显示黑色和白色,现在它的颜色。 我的设备在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);

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

1 个答案:

答案 0 :(得分:0)

似乎自从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);
}
相关问题