android - 抽屉通知图标必须是白色的吗?
问题描述
我的应用程序适用于 API 26 或更高版本。
我对通知中的小图标有疑问。我去了这里的文档,不管我的问题是什么,我看到它提到图标必须是白色的,但是当我现在正在工作时,我正在使用谷歌播客应用程序收听播客,并且图标是彩色的。那么它必须是白色的吗?还是只有谷歌应用可以有颜色?
文档链接: https ://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html
我的问题是,当抽屉关闭时我的图标出现在顶部(它是彩色谷歌播客图标旁边的绿色图标)。但是当drawe打开时,图标不显示,它只是一个空白的绿色圆圈。
这就是我构建通知的方式:
Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(something, ADMIN_CHANNEL_ID)
.setSmallIcon(R.drawable.logo_fallback)
.setLargeIcon(resource)
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("message"))
.setAutoCancel(true)
.setSound(notificationSoundUri)
.setContentIntent(pendingIntent);
//Set notification color to match your app color template
notificationBuilder.setColor(getResources().getColor(R.color.colorPrimaryDark));
notificationManager.notify(notificationID, notificationBuilder.build());
我使用的资源是PNG。我也尝试过 XML,但没有成功。
解决方案
是的,图标应该是白色的,您必须创建一个具有白色和透明功能的图标并设置应有的背景颜色
NotificationCompat.Builder b = new NotificationCompat.Builder(ctx,Const.NOTIFICATION_CHANNEL);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setBadgeIconType(R.drawable.logo)
.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(),R.drawable.logo))
.setContentTitle(title)
.setContentText(message)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
.setContentIntent(contentIntent);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
b.setSmallIcon(R.drawable.new_logo);
b.setColor(ctx.getResources().getColor(R.color.green));
} else {
b.setSmallIcon(R.drawable.logo);
}
这里的 logo 是彩色图标,new_logo 是白色图标
推荐阅读
- java - 从 gRPC 服务返回响应流到 RESTful 客户端的问题
- excel - 如何设置 i 行的复制范围并设置列数
- jquery - jQuery ajax 基本身份验证凭据在浏览器中可见
- python - 将组合的 IntFlag 分解为其单独的标志
- python - 玩家死亡时退出游戏结束
- c# - 检查数据表列名是否为默认列名C#
- r - R ggraph 在指定 facet_edges 时删除隔离
- android - 回收站视图:向上或向下滚动时动画重新启动
- javascript - 在 pug 中编辑表格的单元格并将编辑的数据保存到数据库中
- python - 将 Mnist 数组数据转换为每个像素值的 one-hot 编码数组