我能在Android2.3上同样的TextView中应用Roboto和Roboto粗体吗?
**user** has been publish a beez其中**user**是Roboto粗体,has been publish a beez是Roboto灯光
发布于 2014-03-24 09:53:12
是的,你可以..。
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,如下所示:
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed"https://stackoverflow.com/questions/22605787
复制相似问题