Android TextView指定关键字高亮显示
来源:互联网 发布:cocoapods软件 编辑:程序博客网 时间:2024/04/27 15:51
项目中有这个需求,网上搜了一把,方法挺多的,这里选择一个简单的,已验证可用的方法,记录下,方便以后查阅。
TextView tv = (TextView) findViewById(R.id.hello);SpannableString s = new SpannableString(getResources().getString(R.string.linkify));Pattern p = Pattern.compile("abc");Matcher m = p.matcher(s);while (m.find()) {int start = m.start();int end = m.end();s.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}tv.setText(s);
很简单,tv就是TextView控件,s是要显示的字符串,“abc”是要高亮显示的关键字。
0 0
- Android TextView指定关键字高亮显示
- android textview 关键字高亮显示
- Android 文本阅读以及TextView指定字符高亮显示
- android TextView 实现关键字高亮
- android TextView 实现关键字高亮
- Android TextView中设置关键字高亮
- Android TextView 高亮超链接关键字
- Textview关键字高亮
- Android中TextView的文本内容中指定关键字高亮显示
- TextView高亮显示
- eclipse-以指定颜色高亮显示选中关键字
- eclipse-以指定颜色高亮显示选中关键字
- eclipse-以指定颜色高亮显示选中关键字
- Android TextView 设置超链接、关键字高亮等效果
- Android TextView 设置超链接、关键字高亮等效果
- Android TextView 设置超链接、关键字高亮等效果
- Android ListView 搜索关键字高亮显示
- 高亮显示关键字
- 【杭电-oj】-4505-小Q系列故事——电梯里的爱情
- HDU-5673-Robot(卡特兰数+逆元 / 默慈金数)
- 关于支付宝SDK导入报错的解决办法
- Windows 下使用 RunHiddenConsole 启动 nginx、php
- 使用pip安装tensorflow 0.80,python 使用tensorflow 0.80遇到的问题及处理方法
- Android TextView指定关键字高亮显示
- SAR成像学习(二) “Hello World”版本matlab代码
- 仍是在思过崖攀爬的人
- mysql ERROR 1130: Host ’localhost′ is not allowed to connect to this MySQL server
- 图的邻接矩阵存储---JAVA实现
- CSS规范
- Invalid bound statement (not found)
- python_笔记9_条件过滤
- android waiting for debugger