Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在通知中使用粗体文本_Java_Android - Fatal编程技术网

Java 如何在通知中使用粗体文本

Java 如何在通知中使用粗体文本,java,android,Java,Android,我目前有一个通知,显示发件人和他们发送的邮件。我想用粗体显示名称,但我很难做到这一点。有人知道怎么做吗 Html.fromHtml(String.format(Locale.getDefault(), "<b>%s</b>", wrappedName)) Html.fromHtml(String.format(Locale.getDefault(),“%s”,wrappedName)) 这是我当前正在使用但不起作用的解决方案。 只需使用这行代码即可在通知中获得粗体文本

我目前有一个通知,显示发件人和他们发送的邮件。我想用粗体显示名称,但我很难做到这一点。有人知道怎么做吗

Html.fromHtml(String.format(Locale.getDefault(), "<b>%s</b>", wrappedName))
Html.fromHtml(String.format(Locale.getDefault(),“%s”,wrappedName))

这是我当前正在使用但不起作用的解决方案。

只需使用这行代码即可在通知中获得粗体文本

Html.fromHtml(String.format(Locale.getDefault(), "<strong>%s</strong>", wrappedName));
Html.fromHtml(String.format(Locale.getDefault(),“%s”,wrappedName));
是旧的HTML。对粗体文本(HTML5)使用较新的HTML标记


有一种更好的方法可以实现这一点,而无需使用
formHtml
,请参阅:和。

通常使用InboxStyle比使用HTML部件更好

Spannable sb = new SpannableString("Bold text");
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Notification notification = new Notification.Builder()
     .setContentTitle("5 New mails from " + sender.toString())
     .setContentText(subject)
     .setSmallIcon(R.drawable.new_mail)
     .setLargeIcon(aBitmap)
     .setStyle(new Notification.InboxStyle()
         .addLine(str1)
         .addLine(sb);
         .setContentTitle("")
         .setSummaryText("+3 more"))
     .build();

您是否尝试过
%s
?添加通知代码以更好地帮助您