通知栏图标变成白色的机器人5棒棒糖棒棒糖、机器人、图标、白色

2023-09-12 00:23:41 作者:不做溫柔人

我有一个应用程序显示自定义的通知。问题是,在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 shows white. How can I fix this?

在此先感谢!

推荐答案

接受的答案是不(完全)正确。当然,它使通知图标显示的颜色,但有很大的缺点,这样做 - 由目标SDK设置为比Android棒棒堂下

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的棒棒糖,这意味着你不能使用棒棒糖特定的功能。

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的棒棒糖。

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.

在棒棒糖,谷歌也建议你使用,将在(白)通知图标后面显示一个颜色 - 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棒棒糖。

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 whiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return whiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher;
}
 
精彩推荐
图片推荐