Here is my code and screenshot I\'m trying to set custom font typeface but Runtime exception occurs font asset not found while font file is in asset folder. Am I missing som
the folder name has to be 'fonts' not 'font'
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/" + font);
Your font asset folder is named incorrectly. You should name the folder as fonts
not as font
. Also change your code:
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/terminal.ttf");
Common error when you have assets in your project and you are using the alpha versions of AS. This appears to be a bug in the Android studio build system. A simple workaround is to clean the project before you run it and that should solve the issue that you are facing.
If you use AndroidAnnotations, in app build.gradle, verify if assets folder is ok: ex: main/src/assets.
If you change de font, uninstall your app from your device/emulator, and run again.
Code:
public static void setFontFace(Context context, TextView textView) {
Typeface type = Typeface.createFromAsset(context.getAssets(), "myfont.ttf");
textView.setTypeface(type);
}
I have looked into all the answer but none of them worked for me. I found a new solution after reading the documentation. Here are the steps to follow:
Use in your code using Typeface attribute.
Typeface type = Typeface.createFromAsset(getAssets(), "myfont.ttf"); textView.setTypeface(type);
Now, you are all set to use the fonts you like.