Load a Font using Typeface.createFromFile(File file) in Android-Library project -
i created library project android , i'd load font text using typeface.createfromfile().
i chose typeface.createfromfile(file file) method, because android lib not support assetmanager, can't use typeface.createfromasset(..).
i thinking use raw folder of android resources. inputstream of file context.getresources.openrawresource(r.raw.comic_sans) , can't use in typeface.createfromfile(file file).
another alternative trying use internal storage, don't know if possible move file there in project-time.
if not find solution, can still design lib using assetmanager of application using lib. don't want it.
example want do:
paint textpaint = new paint(); typeface typeface = typeface.createfromfile("comic_sans.ttf"); textpaint.settypeface(typeface);
i believe question how set specific font?
well here how:
- make folder in
app > src > maindirectory of project , call "assets" - download specified
truetype font filewant import (this font want import) - move specified
truetype font fileassets folder - in java class, type in oncreate method :
example code:
typeface test_font = typeface.createfromasset(this.getresources().getassets(),"example_font.ttf"); textview exampletextview = (textview) findviewbyid(r.id.textview1); exampletextview.settypeface(test_font); lastly, import missing
hopefully helps
Comments
Post a Comment