在 Android 上的 TextView 中显示某些单词时,有没有办法使某些单词变为斜体?
我的 Android 应用程序正在 TextView 中显示文本。
是否有任何标签或任何东西可以放在我想要斜体的单词周围?我不需要将 TextView 设置为斜体,因为整个句子就是这样,我只需要将特定单词设置为斜体。
My Android app is displaying text in a TextView.
Are there any tags or anything to put around words that I want italicized? I don't need to set the TextView as italics because the whole sentence would be that way, and I only need specific words italicized.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要使用 Spannable:请参阅 是否有关于 Spanned 和 Spannable 文本的示例作为示例。
You need to use a Spannable: see Is there any example about Spanned and Spannable text for an example.
我同意,这不是数据库问题。如果这不是您正在开发的自定义应用程序,那么您就不走运了。如果是,则将该字段以 HTML 形式保存在数据库中。
I agree, this isn't a database issue. If this is not a custom app you're working on, you're out of luck. If it is, save the field in the database as HTML.
此函数将字符串设置为 TextView 的文本,并以斜体显示该字符串中的一个或多个跨度,只要该跨度用标签 [i] 和 [/i] 标记即可。当然,它可以修改为其他类型的样式。
This function sets a string as the text of a TextView and italicizes one or more spans within that string as long as the span or spans are marked with the tags [i] and [/i]. Of course, it can be modified for other types of styling.
解决方案似乎是将数据库中的内容保存为 HTML,然后在文本视图中输出 HTML。
请参阅以下文章:如何在 TextView 中显示 HTML?
The solution would seem to be to save the content in the database as HTML and then output the HTML in the textview.
See the following article: How to display HTML in TextView?