java - 如何在不使用 xml 的 Java 类中格式化 Java 字符串
问题描述
我设置了一个字符串数组列表来将文本填充到多个介绍屏幕。由于文本填充在实际的 Java 类中,而不是在 xml 资源文件中,我想知道如何在 java 类中使文本中的某些单词变为粗体?
public String [] slide_descriptions = {
"I want this text in bold \n",
"and maybe this too!"
};
解决方案
您可以使用 Html 标签。例如:
textView.setText(Html.fromHtml("< b >This is Bold< /b >"));
对于字符串,这样做:
public String [] slide_descriptions = {
"<b>I want this text in bold</b> \n",
"<b>and maybe this too!</b>"
};
所以最后当你把字符串放在文本视图中时:
textView.setText(Html.fromHtml(slide_description));
推荐阅读
- angularjs - 数据目标可以与路由器一起使用吗
- javascript - 承诺“终于”不起作用
- python - 可以在纱线客户端模式下启动 Dask 吗?
- postgresql - 当 count 与 string_agg 一起使用时在 postgres 中不正确计数?
- java - spring boot 1.5.x /hystrix.stream 执行器不工作
- c++ - libuv - 在没有多线程的情况下限制空闲事件的回调率而不阻塞线程
- npm - 如何查看 node_modules 依赖树?
- powerbi - 在查询编辑器(PowerBI 或 PowerQuery)中引用另一个表
- python - 了解 opencv 的 decomposeHomographyMat 输出
- macos - MacOS:使用 Finder 同步扩展中的 getxattr/setxattr