如何在TextView中使用不同的textAppearance连接两个字符串?

时间:2011-08-26 11:06:47

标签: android android-widget spanned

现在我有了这段代码:

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>的实例放置textApparence android:textAppearance="?android:attr/textAppearanceSmall"。我怎么能这样做?

1 个答案:

答案 0 :(得分:5)

我不知道使用标记<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);