Android 如何在TextView中连接两个具有不同文本外观的字符串?
现在我有了这个代码:Android 如何在TextView中连接两个具有不同文本外观的字符串?,android,android-widget,spanned,Android,Android Widget,Spanned,现在我有了这个代码: TextView textView = (TextView) convertView.findViewById(R.id.label); String html = name + " - <small>" + description + "</small>"; textView.setText(Html.fromHtml(html)); TextView TextView=(TextView)convertView.findViewById(R.i
TextView textView = (TextView) convertView.findViewById(R.id.label);
String html = name + " - <small>" + description + "</small>";
textView.setText(Html.fromHtml(html));
TextView TextView=(TextView)convertView.findViewById(R.id.label);
字符串html=name+“-”+description+”;
setText(Html.fromHtml(Html));
其中textView具有android:textAppearance=“?android:attr/textAppearanceLarge”。但我需要的是
的实例,将textAppearanceandroid:textAppearance=“?android:attr/textAppearanceSmall”
。我如何才能做到这一点?我不知道如何使用标记
,但您可以使用它覆盖部分文本的样式:
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);
我不知道如何使用标记
,但您可以使用它覆盖部分文本的样式:
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);
您好,我不明白您的目的,但为什么不直接在代码中使用
settextearance(context,resId)
方法来更改文本外观?您好,我不明白您的目的,但为什么不直接在代码中使用settextearance(context,resId)
方法来更改文本外观?