Textview关键字高亮
来源:互联网 发布:一橙网络资费 编辑:程序博客网 时间:2024/04/27 15:12
public class TextStringUtil {
/**
* 关键字高亮变色
*
* @param color
* 变化的色值
* @param text
* 文字
* @param keyword
* 文字中的关键字
* @return
*/
public static SpannableString matcherSearchTitle(int color, String text,
String keyword) {
SpannableString s =
new
SpannableString(text);
Pattern p = Pattern.compile(keyword);
Matcher m = p.matcher(s);
while
(m.find()) {
int start = m.start();
int end = m.end();
s.setSpan(
new
ForegroundColorSpan(color), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return
s;
}
/**
* 多个关键字高亮变色
*
* @param color
* 变化的色值
* @param text
* 文字
* @param keyword
* 文字中的关键字数组
* @return
*/
public static SpannableString matcherSearchTitle(int color, String text,
String[] keyword) {
SpannableString s =
new
SpannableString(text);
for
(int i = 0; i < keyword.length; i++) {
Pattern p = Pattern.compile(keyword[i]);
Matcher m = p.matcher(s);
while
(m.find()) {
int start = m.start();
int end = m.end();
s.setSpan(
new
ForegroundColorSpan(color), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return
s;
}
}
0 0
- Textview关键字高亮
- android textview 关键字高亮显示
- android TextView 实现关键字高亮
- android TextView 实现关键字高亮
- 设置TextView的关键字高亮
- Android TextView指定关键字高亮显示
- Android TextView中设置关键字高亮
- Android TextView 高亮超链接关键字
- Android TextView 设置超链接、关键字高亮等效果
- Android TextView 设置超链接、关键字高亮等效果
- Android TextView 设置超链接、关键字高亮等效果
- Android TextView文字设置超链接、背景高亮、关键字高亮等用法
- TextView高亮显示
- Android 高亮 TextView
- 一个让TextView的文本中制定关键字高亮显示的工具类
- 可以高亮显示关键字并设置不同字体大小的自定义TextView
- Android中TextView的文本内容中指定关键字高亮显示
- 搜索关键字高亮。content是全部的String keyWord是关键字。TextView是后面要SET改变的一个TextView
- HDU 3709 Balanced Number(数位dp)
- 面试题201-225
- Python学习笔记(1)
- 文档显示部件,文档编辑部件获取标签的值
- docker安装-官网实例中文(centos7)
- Textview关键字高亮
- JAVA开发网站可以使用什么框架?
- ajax post json数据字符被转义
- 阅读Android源码的一些姿势
- Android样式之drawable
- hdu2089数位dp
- RAM
- MRTG--Quick HOWTO : Ch23 : Advanced MRTG for Linux/zh
- 各个浏览器的内核