当背景颜色为白色时,不会更改Android通知图标颜色 [英] Android notification icon color is not changed when background color is white

查看:634
本文介绍了当背景颜色为白色时,不会更改Android通知图标颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级了android 6.0并且我的应用程序有问题。

I upgraded android 6.0 and my app have problem.

当状态栏背景颜色不是白色时,通知图标很好。
(通知图标png仅包含白色和alpha)

when the status bar background color is not white, notification icon is good. (notification icon png has white and alpha only)

但如果某些应用将背景颜色更改为白色,则我的通知图标不会反转为黑色。

but if some apps change background color to white, my notification icon isn't inverted to black.

当状态栏背景颜色由其他应用设置为白色时,如何将白色通知图标反转为黑色? (我不是说如何使用彩色图标。)

How can I invert white notification icon to black when status bar background color set white by other app? (I'm not saying how can I use color icon.)

图片下方显示问题。

正常状态

当背景颜色变为白色时,我的图标不会变为仅黑色


  • 通知构建代码

  • Notification build code

Notification.Builder mBuilder =
        new Notification.Builder(context)
                .setSmallIcon(R.drawable.ic_notifications_none)
                .setPriority(priority2)
                .setOngoing(true);

mBuilder.setContent(generateMessageView(message));

Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
                          | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent = PendingIntent.getActivity(context, 0,
        notificationIntent, 0);
NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder.setContentIntent(intent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());


  • values-v23 / styles.xml

  • values-v23/styles.xml

    <style name="AppTheme" parent="android:Theme.Material.NoActionBar">            
    </style>
    


  • **找到解决方案**

    ** Found a solution **

    我在drawable目录中添加了通知图标而不是drawable- * dpi。现在它正在运作。

    I added notification icons to drawable directory not drawable-*dpi. Now it's working.

    推荐答案

    现在回答已经很晚了,但对于遇到同样问题的其他人来说,

    It's late to answer, but for others who have the same problem,

    我也有这个问题,我发现问题出在图形图标上。
    您可以使用此在线工具解决问题。
    打开此链接:

    I had this problem too and I found that the problem is with graphical icon. You can solve the problem by using this online tool. open this link:

    https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type = image& source.space.trim = 1& source.space.pad = 0& name = ic_stat_call_white

    选择您的图片(尺寸较大),下载资源并将它们复制到您的项目中。

    choose your image ( with large dimension ), download the resource and copy them to your project.

    最后使用 .setSmallIcon(R.drawable.ICON_NEW_NAME)设置通知图标

    希望这会有所帮助

    这篇关于当背景颜色为白色时,不会更改Android通知图标颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆