Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在TextView中连接两个具有不同文本外观的字符串?_Android_Android Widget_Spanned - Fatal编程技术网

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”。但我需要的是
的实例,将textAppearance
android: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)
方法来更改文本外观?