如何修改iOS系统push notification(推送通知)的文字颜色
推送通知文字颜色修改开发方案
Android 平台
方案1:自定义通知布局(全版本兼容)
- 在res/layout目录下创建自定义布局文件
notification_custom.xml,直接指定文字颜色:
<TextView android:id="@+id/notification_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/black" android:textSize="16sp"/> <TextView android:id="@+id/notification_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/darker_gray" android:textSize="14sp"/>
- 构建通知时加载自定义布局:
// 加载自定义布局 RemoteViews customView = new RemoteViews(getPackageName(), R.layout.notification_custom); customView.setTextViewText(R.id.notification_title, "通知标题"); customView.setTextViewText(R.id.notification_content, "通知内容"); // 构建通知 Notification notification = new NotificationCompat.Builder(context, channelId) .setSmallIcon(R.drawable.ic_notification) .setCustomContentView(customView) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .build();
方案2:系统样式适配(Android 8.0及以上)
不需要自定义布局,通过设置通知背景色触发系统自动适配深色文字:
Notification notification = new NotificationCompat.Builder(context, channelId) .setSmallIcon(R.drawable.ic_notification) .setContentTitle("通知标题") .setContentText("通知内容") .setColorized(true) .setColor(ContextCompat.getColor(context, R.color.white)) .build();
设置白色背景后,系统会自动将标题、内容文字切换为黑色。
iOS 平台
方案1:自定义通知内容扩展
- 新建Notification Content Extension类型的target
- 在扩展的ViewController中修改对应文本控件的颜色:
override func didReceive(_ notification: UNNotification) { self.titleLabel.text = notification.request.content.title self.bodyLabel.text = notification.request.content.body // 设置文字为黑色 self.titleLabel.textColor = .black self.bodyLabel.textColor = .black }
方案2:系统默认通知适配
iOS 15及以上版本,可在通知推送payload中配置背景色为浅色,系统会自动将文字切换为黑色,无需额外代码开发。
注意事项
- 不同厂商的Android定制系统对通知样式的限制不同,上线前需做多机型适配
- 文字颜色和背景色的对比度需要满足WCAG可访问性标准,避免影响用户阅读
- 不要过度修改通知核心样式,否则可能被系统判定为异常通知被拦截
内容的提问来源于stack exchange,提问作者Sarthak
相关产品推荐
相关产品推荐

