首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TextView中的Roboto灯光和Roboto粗体

TextView中的Roboto灯光和Roboto粗体
EN

Stack Overflow用户
提问于 2014-03-24 09:46:54
回答 1查看 1.7K关注 0票数 0

我能在Android2.3上同样的TextView中应用Roboto和Roboto粗体吗?

代码语言:javascript
复制
**user** has been publish a beez

其中**user**是Roboto粗体,has been publish a beez是Roboto灯光

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-24 09:53:12

是的,你可以..。

代码语言:javascript
复制
String firstWord = "user";
String secondWord = "has been publish a beez";

// Create a new spannable with the two strings
Spannable spannable = new SpannableString(firstWord+secondWord);

// Set the custom typeface to span over a section of the spannable object
spannable.setSpan( new CustomTypefaceSpan("sans-serif",CUSTOM_TYPEFACE), 0, firstWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan( new CustomTypefaceSpan("sans-serif-light",SECOND_CUSTOM_TYPEFACE), firstWord.length(), firstWord.length() + secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

// Set the text of a textView with the spannable object
textView.setText( spannable );

您可以从Android 4.1+本地使用Roboto,如下所示:

代码语言:javascript
复制
android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22605787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档