Android @ Friends Resolution && Change colors

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.