是否有可能有多种印刷字体在同一个TextView的? [英] Is it possible to have multiple Typefaces in the same TextView?
本文介绍了是否有可能有多种印刷字体在同一个TextView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何改变文本的属性和颜色的的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);
这篇关于是否有可能有多种印刷字体在同一个TextView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文