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:

  1. make folder in app > src > main directory of project , call "assets"
  2. download specified truetype font file want import (this font want import)
  3. move specified truetype font file assets folder
  4. 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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -