For Guru
For Guru

Reputation: 1197

How to set Roboto Font in Material Design (Best Practice)

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

Upvotes: 0

Views: 6222

Answers (1)

user3144836
user3144836

Reputation: 4148

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.

Upvotes: 6

Related Questions