Reputation: 734
Trying to set the font programmatically.
My file is located in src/main/res/fonts/material_font.ttf
circleProgress.setTextTypeface(Typeface.createFromAsset(assets, "material_font.ttf" ))
and i've tried
circleProgress.setTextTypeface(Typeface.createFromAsset(assets, "fonts/material_font.ttf" ))
circleProgress.setTextTypeface(Typeface.createFromAsset(assets, "font/material_font.ttf" ))
circleProgress.setTextTypeface(Typeface.createFromAsset(applicationContext.assets, "fonts/material_font.ttf" ))
...
The error is:
Font asset not found MaterialIcons-Regular.ttf
What in the world am I doing wrong?
Upvotes: 0
Views: 212
Reputation: 988
Consider doing this if you do not wish to save your font file to assets directory
Typeface typeface = ResourcesCompat.getFont(this, R.font.material_font.ttf);
circleProgress.setTextTypeface(typeface)
Upvotes: 1
Reputation: 3610
we look at the source code and document, for Type.createFromAsset
/**
* Create a new typeface from the specified font data.
*
* @param mgr The application's asset manager
* @param path The file name of the font data in the assets directory
* @return The new typeface.
*/
public static Typeface createFromAsset(AssetManager mgr, String path)
so you should put the font.ttf
in the asset file path
Upvotes: 1