java - Apply styles to text in a string Android -
i'm trying create string spannablestring apply colors , bold text.
spannable wordtospan = new spannablestring("salida de la capilla de maría auxiliadora\n00:00\nmarquesa de sales\n00:00\nespíritu santo\n00:00\nsagasta\n00:00\npza. meneses\n00:00\npozo nuevo\n00:00\npza. ayuntamiento\n00:00\nsan miguel\n00:00\nestación de penitencia, iglesia san miguel\n00:00\nÁnimas\n00:00\nmariano hernández\n00:00\neduardo dato\n00:00\nrojas marcos\n00:00\npza. meneses\n00:00\ncarrera\n00:00\ncalzadilla\n00:00\ngregorio maría ferro\n00:00\nmaría auxiliadora\n00:00\nmarquesa de sales\n00:00\nentrada al templo\n00:00\n"); tv.settext(wordtospan);
to speed work trying create condition this:
if(wordtospan.tostring().contains(":")){ // found text string ":" (00:00) wordtospan.setspan(new foregroundcolorspan(color.rgb(140, 117, 189)), 42, 47, spannable.span_exclusive_exclusive); wordtospan.setspan(new stylespan(typeface.bold), 42,47, 47); }else{ //not found ":" }
i implement bold text , color string 00:00. know quick , easy way? not go telling words words fill 00:00?
regards!
find index of "00:00" , , set start index of span , , end index length of "00:00"
spannable wordtospan = new spannablestring("salida de la capilla de maría auxiliadora\n00:00\nmarquesa de sales\n00:00\nespíritu santo\n00:00\nsagasta\n00:00\npza. meneses\n00:00\npozo nuevo\n00:00\npza. ayuntamiento\n00:00\nsan miguel\n00:00\nestación de penitencia, iglesia san miguel\n00:00\nÁnimas\n00:00\nmariano hernández\n00:00\neduardo dato\n00:00\nrojas marcos\n00:00\npza. meneses\n00:00\ncarrera\n00:00\ncalzadilla\n00:00\ngregorio maría ferro\n00:00\nmaría auxiliadora\n00:00\nmarquesa de sales\n00:00\nentrada al templo\n00:00\n"); string search = new string("00:00"); int length = search.length(); string input = wordtospan.tostring(); int startindex = input.indexof(search); while(startindex > length) { wordtospan.setspan(new foregroundcolorspan(color.rgb(140, 117, 189)), startindex, startindex + length, spannable.span_exclusive_exclusive); wordtospan.setspan(new stylespan(typeface.bold), startindex, startindex + length, spannable.span_exclusive_exclusive); startindex = input.indexof(search, startindex + length); }
you have loop throughout string index
Comments
Post a Comment