Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 文本视图中的Roboto light和Roboto bold_Java_Android_Textview_Spannablestring - Fatal编程技术网

Java 文本视图中的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

我可以在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
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没有定义。