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;
}
相关文章
- 09-25android: 菜单在toolbar中的改变item字体颜色以及背景
- 09-25改变Android ProgressBar样式颜色
- 09-25Android学习第八弹之改变状态栏的颜色使其与APP风格一体化
- 09-25Android基础TOP2:单机按钮改变字体颜色
- 09-25如何改变Android标准键的颜色?
- 09-25Android 改变字体颜色的三种方法
- 09-25Android(java)学习笔记35:如何改变Spinner系统自带的字体和颜色
- 09-25android 自定义 radiobutton 文字颜色随选中状态而改变
- 09-25android自定义控件实现TextView按下后字体颜色改变
- 09-25改变Android按钮背景颜色的高效方法