我知道如何改变文本的属性和颜色的的TextView
在Android的,但有可能有多个字样
在同一个的TextView
?例如,我可以在同一时间在同一个的TextView
同时使用德罗伊德桑和Droid的单?如果是这样,怎么样?
I know how to change text attributes and color for a TextView
in Android, but is it possible to have multiple Typefaces
in the same TextView
? For example, can I use both Droid Sans and Droid Mono in the same TextView
at the same time? If so, how?
其实它看起来像你可以用Spannable的帮助下做到这一点:
Actually it looks like you can do it with the help of a Spannable:
String text = "This is an example";
Spannable s = new SpannableString(text + " text");
s.setSpan(new TypefaceSpan("monospace"), 0, text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(new TypefaceSpan("serif"), text.length(), s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
((TextView)findViewById(R.id.my_text_view)).setText(s);