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

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 @好友解析&&改变颜色

上一篇:问题:从键盘读取特定类型的数据(使用Scanner读取int类型)


下一篇:Android SDK开发包国内下载地址