Java 文本视图中的Roboto light和Roboto bold
我可以在Android 2.3的同一文本视图中应用Roboto light和Roboto bold吗Java 文本视图中的Roboto light和Roboto bold,java,android,textview,spannablestring,Java,Android,Textview,Spannablestring,我可以在Android 2.3的同一文本视图中应用Roboto light和Roboto bold吗 **user** has been publish a beez 其中,**用户**为机器人粗体,已发布beez为机器人灯光是的,您可以这样做 String firstWord = "user"; String secondWord = "has been publish a beez"; // Create a new spannable with the two strings Span
**user** has been publish a beez
其中,**用户**
为机器人粗体,已发布beez
为机器人灯光是的,您可以这样做
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"
您必须首先在资产/字体文件夹中下载。然后按本节所述访问该字体。最后将其与Lokesh的答案放在一起。CustomTypefaceSpan没有定义。