【问题标题】:Notification bar icon turns white in Android L通知栏图标在 Android L 中变为白色
【发布时间】:2017-10-26 15:29:34
【问题描述】:

我正在使用远程视图进行自定义通知布局。一切正常。我面临的唯一问题是通知在通知状态栏中显示为白色圆圈。我希望我的应用程序图标显示在通知状态栏中(它在 kitkat 和更低版本中的显示方式)。有什么办法可以改变吗?

private void showNotification() {

        Intent intent = new Intent(this, HomeActivity.class);
        intent.putExtra(LIVE_RADIO_PUSH, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
        mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setCategory(Notification.CATEGORY_SERVICE);
        mBuilder.setContentTitle(mTitle);
        mBuilder.setContentText("Live Radio");
        mBuilder.setSmallIcon(R.drawable.logo);
        mBuilder.setWhen(System.currentTimeMillis());
        mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
        mBuilder.setContentIntent(pendingIntent);
        mBuilder.setColor(getResources().getColor(R.color.theme_primary));
        mNotificationView = new RemoteViews(getPackageName(), R.layout.notification_layout);
        mNotificationView.setTextViewText(R.id.content_title, mTitle);
        mNotificationView.setTextViewText(R.id.content_text, "Live Radio");
        SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm");
        String time = dateFormat.format(new Date(System.currentTimeMillis()));
        mNotificationView.setTextViewText(R.id.current_time, time);
        mNotificationView.setImageViewResource(R.id.play_pause, R.drawable.pause_radio);
        mNotificationView.setImageViewResource(R.id.close_btn, R.drawable.notifictn_close_btn);


        setListeners(mNotificationView);
        mBuilder.setContent(mNotificationView);
        Log.d(TAG, "App is freezed2");
        if (null != mNotificationMngr)
            mNotificationMngr.notify(RADIO_NOTIFICATION_ID, mBuilder.build());
    }

【问题讨论】:

  • 发布您的通知代码
  • @Ramesh 更新了我的代码

标签: android notifications android-5.0-lollipop


【解决方案1】:

我也遇到过这个问题,正如你所说,如果你的 ANDROID_BUILD_TARGET_SDK_VERSION = 21,它会将这个通知变成白色。

此链接的通知图标设计指南。 http://developer.android.com/design/style/iconography.html

【讨论】:

  • 我将 minSdkVersion 设置为 8,将 targetSdkVersion 设置为 17,但在运行 Android 6.0 的设备上仍然遇到同样的问题。有没有其他人经历过这种行为?
【解决方案2】:

最近我们做了一个带有通知的应用程序。它在棒棒糖中也可以正常工作。一旦检查下面的代码可能会对你有所帮助。

mNotification = new Notification.Builder(this).setContentTitle("M3 Media Player").setContentIntent(mPendingIntentHome)
                    .setSmallIcon(R.drawable.app_icon).setPriority(Notification.PRIORITY_MAX).setContent(mNotificationContentView)
                    .setStyle(new Notification.BigPictureStyle()).build();

【讨论】:

  • 我的通知工作正常。唯一的问题是在状态栏中它显示为白色。但是当我打开通知区域时,它会正确显示。我的问题是如何将白色更改为通知图标?
  • 另外,我参考了这个链接:stackoverflow.com/questions/28387602/… 他们所说的,这是因为棒棒糖中的设计发生了变化。 // statusbar/BaseStatusBar.java if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) { entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white)); } else { entry.icon.setColorFilter(null); }
【解决方案3】:

如果您的 compileSDKversion 高于 20,则通知图标应该是白色透明背景图像。否则图像将呈现为白色图像。

请也通过以下链接获取创建图标的指南

https://www.google.com/design/spec/patterns/notifications.html

还有通知图标生成器。

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

【讨论】:

  • 但是今天大部分的应用程序图标仍然是彩色的。这怎么可能?我不认为他们用旧的 SDK 编译,是吗?