As follows:
The key code is as follows:
StringBuffer sb = new StringBuffer (); if (Day > 0) {sb.append ("<a href=\" 1\ ">"); Sb.append ("+day"); Sb.append ("</a>"); Sb.append ("+global.getstring (R.string.unit_day2)"); } sb.append ("<a href=\" 2\ ">"); if (Hour > 9) {sb.append ("" +hour); } else {sb.append ("0" +hour); } sb.append ("</a>"); Sb.append ("+global.getstring (R.STRING.UNIT_HOUR2)"); Sb.append ("<a href=\" 3\ ">"); if (Minute > 9) {sb.append ("" +minute); } else {sb.append ("0" +minute); } sb.append ("</a>"); Sb.append ("+global.getstring (R.string.unit_minute2)"); Sb.append ("<a href=\" 4\ ">"); if (Second > 9) {sb.append ("" + second); } else {sb.append ("0" + second); } sb.append ("</a>"); Sb.append ("+global.getstring (R.string.unit_second)"); int end = Sb.length (); spannablestring ss = new Spannablestring (html.fromhtml (sb.tostring ())); urlspan[] urls = Ss.getspans (0, end, Urlspan.class); String resultstr = sb.tostring (); Pattern p_html = Pattern.compile (regex_html, pattern.case_insensitive); Matcher m_html = P_html.matcher (RESULTSTR); ResultStr = M_html.replaceall (""); Filter HTML tags spannablestring span = new spannablestring (RESULTSTR); for (Urlspan url:urls) {int startIndex = Ss.getspanstart (URL); int endIndex = ss.getspanend (URL); Original word twice times size span.setspan (new absolutesIzespan (GLOBAL.DPTOPX ()), StartIndex, EndIndex, spannable.span_exclusive_exclusive); Set style 2 Span.setspan (new Foregroundcolorspan (Color.White), star Tindex, EndIndex, spannable.span_exclusive_inclusive); Set Style 3 Span.setspan (new Stylespan (Typeface.bold), StartIndex, EndIndex, spannable.span_exclusive_inclusive); } mbottomll2_detail.settext (span);
Description
1. The main principle is to use spannablestring to long style string to TextView display
2. The reason for using the <a href> label is to be internationalized, because span is diversified according to index, so it is necessary to use HREF to identify a variety of index