Reputation: 4762
My Folder Structure
Code for font:
Typeface typeface = Typeface.createFromAsset(this.getAssets() , AppContants.ROBOT_MEDIUM);
My Source set:
sourceSets {
main { java.srcDirs = ['src/main/java', 'src/main/res/xml']
assets.srcDirs = ['src/main/java/assets']
}
}
Getting Null pointer for this Typeface instance.
Upvotes: 0
Views: 1115
Reputation: 659
Add fonts folder to your path. Move your .ttf files to the fonts folder.
sourceSets {
main { java.srcDirs = ['src/main/java', 'src/main/res/xml']
assets.srcDirs = ['src/main/java/assets/fonts']
}
}
Upvotes: 2
Reputation: 669
Put your font file in assets/fonts
directory an then,
Simply use :
Typeface tf = Typeface.createFromAsset(getBaseContext().getAssets(),
fontPath);
where fontPath
is the path to your font file in assets folder.
fontPath = "fonts/<your_font_file_name>"
Hope this Helps!
Upvotes: 1