android - Set textColorLink on textAllCaps? -


i have textview should in caps , mark urls found in specific color, naturaly i've tried textcolorlink, option textallcaps="true", url not colored, guess regex not match uppercase urls, since url colored if same text in lowercase.

i've tried solving this:

spannable formatted = new spannablestring(text); pattern url = pattern.compile(             "(https?)://[-a-za-z0-9+&@#/%?=~_|!:,.;]*[-a-za-z0-9+&@#/%=~_|]"); matcher matcher = url.matcher(text.tolowercase());  while (matcher.find()) {     log.e("test",matcher.group());     int begindex = matcher.start();     int endidx = begindex + matcher.group().length() - 1;     log.e("found", string.valueof(begindex));     formatted.setspan(new foregroundcolorspan(                     getresources().getcolor(android.r.color.holo_red_light)),                 begindex, endidx, spannable.span_exclusive_exclusive); } mtextview.settext(formatted); 

apparently finds text, once again not colored. i've been @ hours, how solve this?

when try uppercase string lose color if add spannablestring , pass string.touppercase can setspan...

spannablestring formatted = new spannablestring(urlstring); pattern url = pattern.compile("(https?)://[-a-za-z0-9+&@#/%?=~_|!:,.;]*[-a-za-z0-9+&@#/%=~_|]"); matcher matcher = url.matcher(urlstring.tolowercase());  //here save string in upper case spannablestring stringuppercase = new spannablestring(formatted.tostring().touppercase());  while (matcher.find()) {     int begindex = matcher.start();    int endidx = begindex + matcher.group().length() - 1;    stringuppercase.setspan(new foregroundcolorspan(r.color.red),                         0, formatted.length(), spannable.span_exclusive_exclusive);             } textview text = (textview) findviewbyid(r.id.textview); text.settext(string); 

should works...


remove xml textallcaps="true"


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -