android - 设置通知栏图标颜色
解决方案
在构建通知时,您可以设置颜色和图标。(如果您的图标是纯白色图像,它会在正确的位置为您应用颜色。)
这是我最近使用的代码
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationId = 10 // Some unique id.
// Creating a channel - required for O's notifications.
val channel = NotificationChannel("my_channel_01",
"Channel human-readable title",
NotificationManager.IMPORTANCE_DEFAULT)
manager.createNotificationChannel(channel)
// Building the notification.
val builder = Notification.Builder(context, channel.id)
builder.setContentTitle("Warning!")
builder.setContentText("This is a bad notification!")
builder.setSmallIcon(R.drawable.skull)
builder.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
builder.setChannelId(channel.id)
// Posting the notification.
manager.notify(notificationId, builder.build())
}
在第一行检查您手机的版本,并据此获得通知样式
建设者。小图标和builder.set颜色(给你想要的颜色)
推荐阅读
- html - 调整视口大小会在固定的 div 之间产生不需要的空间(不是 css 内联)
- java - Android 9 你能推荐一个后台服务吗
- java - 如何将自定义布局用作表格布局中的视图
- php - PHP 找不到文件路径
- javascript - html表单在提交时没有调用正确的函数
- javascript - 如何从 Electron 的渲染器中获取节点模块?
- python - Azure 认知服务:如何在说话人识别 API 中传递多个 IdentificationProfileId
- java - 如何在Java中显示小数点前没有前导零的双精度数
- android - Android openCV 相机无法正常工作
- c# - Angular 8 + Jwt + [Authorize] + DotNet Core 2.1 Api + Chrome 发布请求失败并出现 cors 错误