android - android中通知图标的颜色

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

当我在 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/

相关文章:

java - onOptionsItemSelected Hook 调用了错误的 fragment

node.js - Chatbot 消息不会显示在 Facebook Messenger 聊天头像中

来自 Mac OS 的 USB 设备添加/删除通知

android - 使用 accessibilityservice android 获取通知消息

android - iOS 或 Android 应用程序可以与其他应用程序交互推送通知吗?

java - Eclipse Android 开发 - [I18N] 硬编码字符串 "TextView",应该使用 @string 资源

android - 按电源按钮关闭屏幕正在重新启动 Activity

android - 如何删除 Android ViewPager 中的页面?

php - 在我的 Android 应用程序上使用 GCM 推送通知

ios - 应用关闭时推送通知的行为不同