通知状态栏图标不会变为白色

问题描述 投票:0回答:3

正如标题所说,当我启动i时,通知状态栏上的小图标不会将颜色变为白色并且几乎不可见:

enter image description here

enter image description here

Notification n  = new Notification.Builder(this)
        .setContentTitle("title")
        .setContentText("lorem ipsum dolor sit amet")
        .setSmallIcon((R.drawable.logo_ntf))
        .setLargeIcon(icon)
        .setAutoCancel(true)
        //.addAction(R.drawable.transparent, null, null)
        .build();
android android-notifications android-notification-bar
3个回答
0
投票

对于Android 5+,您必须为通知小图标创建透明图标。

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notification.setSmallIcon(R.drawable.icon_transperent);
    notification.setColor(getResources().getColor(R.color.notification_color));
} else { 
    notification.setSmallIcon(R.drawable.icon);
}

查看this了解更多信息


0
投票

原因:对于5.0 Lollipop“通知图标必须完全是白色”。

如果我们通过将目标SDK设置为20来解决白色图标问题,我们的应用程序将不会针对Android Lollipop,这意味着我们无法使用Lollipop特有的功能。

针对以下Lollipop OS版本的Notification Builder的实现将是:

Notification notification = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notification.setSmallIcon(R.drawable.icon_transperent);
    notification.setColor(getResources().getColor(R.color.notification_color));
} else { 
    notification.setSmallIcon(R.drawable.icon);
} 

reference link,还阅读文档5.0 Behavior Changes


0
投票

确保可绘制文件的透明度后....

尝试将以下内容添加到Notification.Builder管道:

.setColor(color);

color应该是一个资源int值,引用一个颜色,如下所示:

int color = getResources().getColor(R.color.notification_color);

不推荐的方式:

int color = ContextCompat.getColor(context, R.color.notification_color);

资料来源:setColor documentation

© www.soinside.com 2019 - 2024. All rights reserved.