字符串拼接工具类
2015-12-13 22:16
399 查看
public class StringUtil { /** * 把str填充到上面的sourceID中的%1$s * @param context * @param textView * @param sourceID String.xml里面的字符串,eg:name="weather_type"对应"天气状况:%1$s" * 就是这里的weather_type * @param str 需要填充的字符串 */ public static void setFormatText(Context context,TextView textView,int sourceID,String str){ String tipFormat = context.getResources().getString(sourceID); textView.setText(String.format(tipFormat, str)); } /** * 使关键字高亮 * @param context * @param textView * @param complete 完整String串 * @param keyword 完整串中需要高亮的关键字 */ public static void highNightKeyword(Context context ,TextView textView,String complete,String keyword){ int index =complete.indexOf(keyword); SpannableStringBuilder builder = new SpannableStringBuilder(complete); ForegroundColorSpan highLightSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.navi_search_hightlight)); builder.se 8ed0 tSpan(highLightSpan, index, index + keyword.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(builder); } }
相关文章推荐
- 在提高班如何学习
- 关于Filter解决全网乱码问题的总结 --- 包装类 编解码 过滤器
- 线程同步之事件对象
- How to Learn R
- [开源学习]SwipeMenuListView源码实现过程解析
- 求助在sql 2012中不能用compute by语句
- C++学生成绩排序
- HDU 1087 最大递增字段和
- ReactJs入门介绍
- AngularJS 对象
- 互联网追梦第一人:90后福建潘华鹏的传媒人生
- C语言基础(二)
- 第一天
- [javase学习笔记]-5.2 数组的内存分配及特点
- 简读The Swift Programming Language官方文档--枚举
- Phone状态的监听机制
- ios CoreData NSManagedObject 生命周期
- 程序员必须软件
- 【leetcode题解】【E】【59】Reverse Bits
- 简读The Swift Programming Language官方文档--控制流