我可以像这样在Android 2.3的同一TextView中应用Roboto light和Roboto bold吗?
**user** has been publish a beez
其中
**user**
是Roboto粗体,而has been publish a beez
是Roboto light 最佳答案
是的,你可以做..
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"
关于java - TextView中的Roboto light和Roboto粗体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22605787/