2011-08-26 18 views
0

現在我有這樣的代碼:如何在TextView中連接具有不同文本外觀的兩個字符串?

TextView textView = (TextView) convertView.findViewById(R.id.label); 
String html = name + " - <small>" + description + "</small>"; 
textView.setText(Html.fromHtml(html)); 

哪裏的TextView有android:textAppearance="?android:attr/textAppearanceLarge"。但我需要的是<small>的實例把文本Apparence android:textAppearance="?android:attr/textAppearanceSmall"。我怎樣才能做到這一點?

+0

嗨,我不明白你的目的,但你爲什麼不使用'setTextAppearance(上下文,resId)'方法直接在你的代碼中改變文本外觀? –

回答

4

我不知道用標籤<small>,但你可以用它來覆蓋樣式文本的一部分:

SpannableStringBuilder sb = new SpannableStringBuilder(); 
sb.append("name - "); 
int start = sb.length(); 
sb.append("description"); 
sb.setSpan(new TextAppearanceSpan(this, android.R.style.TextAppearance_Small), start, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
sb.append(" - "); 
myText.setText(sb); 
相關問題