Android 5 Lollipop 中的通知栏图标变为白色

Notification bar icon turns white in Android 5 Lollipop(Android 5 Lollipop 中的通知栏图标变为白色)
本文介绍了Android 5 Lollipop 中的通知栏图标变为白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示自定义通知的应用.问题是在 Android 5 中运行时,通知栏中的小图标显示为白色.我该如何解决这个问题?

I have an app showing custom notifications. The problem is that when running in Android 5 the small icon in the Notification bar is shown in white. How can I fix this?

推荐答案

接受的答案不(完全)正确.当然,它使通知图标显示为彩色,但这样做有一个很大的缺点 - 将目标 SDK 设置为低于 Android Lollipop!

The accepted answer is not (entirely) correct. Sure, it makes notification icons show in color, but does so with a BIG drawback - by setting the target SDK to lower than Android Lollipop!

如果您按照建议通过将目标 SDK 设置为 20 来解决白色图标问题,您的应用将不会以 Android Lollipop 为目标,这意味着您无法使用 Lollipop 特定的功能.

If you solve your white icon problem by setting your target SDK to 20, as suggested, your app will not target Android Lollipop, which means that you cannot use Lollipop-specific features.

看看 http://developer.android.com/design/style/iconography.html,您会看到白色样式是通知在 Android Lollipop 中的显示方式.

Have a look at http://developer.android.com/design/style/iconography.html, and you'll see that the white style is how notifications are meant to be displayed in Android Lollipop.

在 Lollipop 中,Google 还建议您使用将显示在(白色)通知图标后面的颜色 - https://developer.android.com/about/versions/android-5.0-changes.html

In Lollipop, Google also suggest that you use a color that will be displayed behind the (white) notification icon - https://developer.android.com/about/versions/android-5.0-changes.html

所以,我认为更好的解决方案是在应用中添加一个剪影图标,并在设备运行 Android Lollipop 时使用它.

So, I think that a better solution is to add a silhouette icon to the app and use it if the device is running Android Lollipop.

例如:

Notification notification = new Notification.Builder(context)
            .setAutoCancel(true)
            .setContentTitle("My notification")
            .setContentText("Look, white in Lollipop, else color!")
            .setSmallIcon(getNotificationIcon())
            .build();

    return notification;

并且,在 getNotificationIcon 方法中:

And, in the getNotificationIcon method:

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher;
}

这篇关于Android 5 Lollipop 中的通知栏图标变为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)