I'm trying to load a custom font as follows:
private Paint customFont18;
customFont18 = new Paint();
customFont18.setTextSize(18);
Typeface fontFace = Typeface.createFromAsset(getAssets(), "FONT.TTF");
customFont18.setTypeface(fontFace);
The getAssets fails, thows this:
-The method getAssets() is undefined for the type MyClass
-assetManager cannot be resolved to a variable
What is my problem? I've seen several examples like this but none works in my case. Thanks in advance.
getAssets() is a method of Context. If your class is not an activity, you'll need to pass a context into it and then call getAssets() on that.
public myClass(Context myContext) {
Typeface typeface = Typeface.createFromAsset(myContext.getAssets(), "FONT.TTF");
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With