目前分類:Android (2)
- May 23 Thu 2013 12:01
Android Studio 豐富的Layout預覽功能
- Jun 26 Tue 2012 12:25
Android TextView Clickable (not URL)
1.Processing Text 處理字串
Input: original text 原始字串
Output: edited text 編輯後字串
// neMAp = <span content, span id> private HashMap neMap = new HashMap(); // neLength = span content length private ArrayList neLength = new ArrayList(); // get <span> id and content // replace <span>content</span> to <util>content // 取得<span>的id和所包的文字內容 // 將<span>文字內容</span>換成<util>content private String parseContent(String text) { String[] contArray = text.split("<span id=\""); ArrayList keyArray = new ArrayList(); for (String ca : contArray) { String span = ca.split("</span>")[0]; keyArray.add(span); } for(int i = 1 ; i < keyArray.size() ; i++){ String[] temp = keyArray.get(i).split("\">"); neMap.put(temp[1], temp[0]); neLength.add(temp[1].length()); text = text.replace("<span id=\""+temp[0]+"\">"+temp[1]+"</span>", "<util>"+temp[1]); } return text; }
2.Set SpannableStringBuilder 設定字串Span