码迷,mamicode.com
首页 > 移动开发 > 详细

Android @好友解析&&改变颜色

时间:2014-08-14 10:36:08      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:android   color   os   for   ar   art   amp   new   

private static SpannableStringBuilder afterGetName(String str) {

        List<Integer> starts = new ArrayList<Integer>();
        List<Integer> ends = new ArrayList<Integer>();
        SpannableStringBuilder result = new SpannableStringBuilder(str);
        Pattern pattern1 = Pattern.compile("@[\\[].+?[:].+?[\\]]");
        Matcher matcher1 = pattern1.matcher(result);
        while (matcher1.find()){
            int i = matcher1.start();
            starts.add(i);
            String currentStr = matcher1.group();
            String[] name = currentStr.split(":");
            String name1 = name[1];
            StringBuilder stringBuilder = new StringBuilder(name1);
            stringBuilder.delete(name1.length()-1,name1.length());
            stringBuilder.insert(0, "@");
            String str1 = matcher1.replaceFirst(stringBuilder.toString());
            int j = i+stringBuilder.length();
            ends.add(j);
            result = new SpannableStringBuilder(str1);
            matcher1 = pattern1.matcher(result);
        }
        for(int m = 0 ; m < starts.size(); m++){
            ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#ff548dff"));
            int j = starts.get(m);
            int k = ends.get(m);
            result.setSpan(span, j, k, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return result;
    }

Android @好友解析&&改变颜色,布布扣,bubuko.com

Android @好友解析&&改变颜色

标签:android   color   os   for   ar   art   amp   new   

原文地址:http://www.cnblogs.com/chenxinwen/p/3911798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!