0

Can I apply Roboto light and Roboto bold in same TextView on Android 2.3 like that?

**user** has been publish a beez

Where **user** is Roboto bold and has been publish a beez is Roboto light

Cristian
  • 514
  • 4
  • 21
  • You have to download the [ROBOTO font](https://developer.android.com/design/downloads/index.html) in your assets/fonts folder, first. Then access that font as described in this [post](http://stackoverflow.com/a/6746775/2649012). And finally put it together with Lokesh's answer. – Phantômaxx Mar 24 '14 at 09:55

1 Answers1

2

Yes you can do ..

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 );

You can use Roboto natively from Android 4.1+ like this:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed"
Lokesh
  • 5,180
  • 4
  • 27
  • 42