You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改iOS系统push notification(推送通知)的文字颜色

推送通知文字颜色修改开发方案

Android 平台

方案1:自定义通知布局(全版本兼容)

  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"/>
  1. 构建通知时加载自定义布局:
// 加载自定义布局
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:自定义通知内容扩展

  1. 新建Notification Content Extension类型的target
  2. 在扩展的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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 14:45:01