【问题标题】:In oreo notification icon color is grey in Android在 Android 中,奥利奥通知图标颜色为灰色
【发布时间】:2019-01-22 23:44:04
【问题描述】:

通知图标在 android 8.0 中为灰色。我想显示应用程序图标。我试过以下代码:

  <meta-data 
   android:name="com.google.firebase.messaging.default_notification_icon"
   android:resource="@drawable/ic_launcher_round" />

但它不起作用。请帮忙!

【问题讨论】:

  • 你想要什么?
  • 我想用图标代替灰色

标签: android android-8.0-oreo


【解决方案1】:

代码应该是这样的:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/statusbar_notification" />

更多信息请点击此处链接:Oreo (8.0) status bar notification icon all white

希望能帮到你。

【讨论】:

  • 感谢您的回答。我可以知道我的代码和您的代码之间的区别是什么,只是名称或其他任何内容?
  • 仅限resource数据
  • 我不明白。我的图像也在可绘制资源中。我只需要更改名称吗?
【解决方案2】:

试试这个 sn-p - 希望它能解决你的问题。

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);

//building some actions...

builder.setSmallIcon(R.mipmap.ic_launcher_round)
                .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(0, 1, 2)
                        .setShowCancelButton(true)
                        .setMediaSession(mediaSessionCompat.getSessionToken()))
                .setCategory(NotificationCompat.CATEGORY_TRANSPORT)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setShowWhen(false)
                .setContentTitle("Title Name")
                .setContentText("Content text")
                .setSmallIcon(R.drawable.pause)
                .setWhen(0)
                .setAutoCancel(true)
                .setLargeIcon(icon);

更多详情请看官方文档- Notification Overview

【讨论】:

  • 感谢回答。什么是 mediaSessionCompat?
  • 我使用 MediaSession 作为通知音频播放器。如果不需要,可以删除 mediasession。
猜你喜欢
  • 1970-01-01
  • 2018-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
相关资源
最近更新 更多