英文:
How do you set Bold style for specific word in android?
问题
我已经知道我们可以这样做,但那些不是供我使用的。我希望它只在设置的文本内,而不在 Java 中创建任何新的字符串。我在stackoverflow上已经找到了很多类似的问题,但在我的情况下它们都不适用。
以下是我尝试过的代码:
printResult.setText(String.valueOf(Html.fromHtml("<b>" + printNumbers + "</b>")));
英文:
I already know how we can do that, but those are not for my use. I want it just within set text without creating any new string in java. I found many questions already on stackoverflow, But they all are different for me in this case.
Here what i've tried :
printResult.setText(String.valueOf(Html.fromHtml("<b>" +printNumbers+ "</b>" )));
答案1
得分: 0
方法 String.valueOf() 会将 Spannable 转换为 String,导致您格式化的字符串丢失。因此,请移除 String.valueOf() 方法,并使用以下代码:
printResult.setText(Html.fromHtml("<b>" + printNumbers + "</b>"));
英文:
The method String.valueOf() will convert the Spannable to String and your formatted string will lost. So, remove the String.valueOf() method and use below code:
printResult.setText(Html.fromHtml("<b>" +printNumbers+ "</b>" ));
专注分享java语言的经验与见解,让所有开发者获益!

评论