0

I want to set Roboto font in Material Design. Shall I need to add font in Asset Folder as I used to do previously. I know how to set custom font to any View but want to use for Material Design. My application will be used on Android 3.0 and onward.

I have been using following to use custom fonts

public static Typeface getTypeFace() {
    if (fromAsset == null) {
        fromAsset = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Medium.ttf");
    }
    return fromAsset;
}
For Guru
  • 1,197
  • 13
  • 23

1 Answers1

6

Since your application will be used on Android 3.0 you should keep your fonts in the Asset folder for backward compatibility otherwise for Android 4.1.+ you can simply do this

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

Please see this answer for more details.

Community
  • 1
  • 1
user3144836
  • 4,060
  • 3
  • 27
  • 27