在 Android 中使用 Html.fromHtml() 突出显示文本颜色? [英] Highlighting Text Color using Html.fromHtml() in Android?

查看:19
本文介绍了在 Android 中使用 Html.fromHtml() 突出显示文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中将有一个搜索屏幕用户可以在其中搜索特定关键字,并且该关键字应该是突出显示.我找到了 Html.fromHtml 方法.

I am developing an application in which there will be a search screen where user can search for specific keywords and that keyword should be highlighted. I have found Html.fromHtml method.

但我想知道这是正确的做法还是不是.

But I will like to know whether its the proper way of doing it or not.

请告诉我您对此的看法.

Please let me know your views on this.

推荐答案

或者比手动处理 Spannable 简单得多,因为你没有说要突出背景,只是文本:

Or far simpler than dealing with Spannables manually, since you didn't say that you want the background highlighted, just the text:

String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);

这篇关于在 Android 中使用 Html.fromHtml() 突出显示文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆