简体   繁体   English

SpannableStringBuilder 将字符串部分设置为粗体不起作用

[英]SpannableStringBuilder setting String partially as bold not working

I'm using SpannableStringBuilder to set a string partially with a style of bold, however it's not working and I am unsure of what I am doing incorrectly.我正在使用 SpannableStringBuilder 设置部分带有粗体样式的字符串,但是它不起作用,我不确定我做错了什么。

String normalText = "New Here? ";
String boldText = "Register";
        
SpannableStringBuilder str = new SpannableStringBuilder(normalText + boldText);
tr.setSpan(new StyleSpan(Typeface.BOLD), normalText.length(), str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mBtnRegister.setText(str);

I've followed this SO example:我遵循了这个 SO 示例:

https://stackoverflow.com/a/41460376/11110509 https://stackoverflow.com/a/41460376/11110509

The specified code looks to be working well as visible in the screenshot here: https://imgur.com/a/1cOLQrC指定的代码看起来运行良好,如此处的屏幕截图所示: https://imgur.com/a/1cOLQrC

Please check your code for other mistakes causing wrong behavior.请检查您的代码是否存在导致错误行为的其他错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM