要更改操作文本颜色,请使用:
HtmlCompat.fromHtml("<font color=\"" + ContextCompat.getColor(context, R.color.custom_color) + "\">" + context.getString(R.string.fire) + "</font>", HtmlCompat.FROM_HTML_MODE_LEGACY)
Run Code Online (Sandbox Code Playgroud)
作为动作标题CharSequence,例如:
Notification notification = new NotificationCompat.Builder(context, channelId)
...
.addAction(new NotificationCompat.Action.Builder(
R.drawable.ic_fire,
HtmlCompat.fromHtml("<font color=\"" + ContextCompat.getColor(context, R.color.custom_color) + "\">" + context.getString(R.string.fire) + "</font>", HtmlCompat.FROM_HTML_MODE_LEGACY),
actionPendingIntent))
.build())
.build();
Run Code Online (Sandbox Code Playgroud)
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
Run Code Online (Sandbox Code Playgroud)
NotificationCompat.Builder.setColor 方法用于设置通知的强调颜色,该颜色也将应用于操作按钮的文本。
要更改操作的文本颜色并在其左侧放置一个图标,请使用以下示例。
NotificationCompat.Builder(context).setColor(ContextCompat.getColor(context, R.color.yourColorResourceHere))
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Fire", myPendingIntent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4754 次 |
| 最近记录: |