Is it possible to have multiple Typefaces in the same TextView?

怎甘沉沦 提交于 2019-12-18 03:35:12

问题


I know how to change text attributes and color for a TextView, but is it possible to have multiple Typefaces in the same TextView?
For instance, can I use both Droid Sans and Droid Mono in the same TextView at the same time?

If so, how?


回答1:


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);


来源:https://stackoverflow.com/questions/7036685/is-it-possible-to-have-multiple-typefaces-in-the-same-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!