我可以在Android 2.3上的同一TextView中应用Roboto light和Roboto粗体吗?
**user** has been publish a beez
其中**user**
是Roboto粗体,而has been publish a beez
是Roboto light
答案 0 :(得分:3)
是的,你可以做..
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"