Android Typeface createFromAsset -


i have custom view draws text onto canvas. want change font font stored in assets folder.

i using android studio created folder src/main/assets , placed ttf files in there.

paint txt = new paint() typeface font = typeface.createfromasset(getassets(), "robotobold.ttf"); txt.settypeface(font); 

problem android studio doesn't recognize getassets() inside custom view, recognizes inside activity. have tried passing typeface through activity when it doesn't change font.

you can use view's getcontext() method current context, use assets:

typeface font = typeface.createfromasset(getcontext().getassets(), "robotobold.ttf"); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -