0

I have to use custom fonts in my application. I know how to read a font from the assets directory and apply them to a control, however this seems a very laborious task.

Is there anyway I can apply a custom font from my assets directory to all the controls in the application.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
AndroidDev
  • 15,993
  • 29
  • 85
  • 119
  • Here the answer for your question... write an customtextview extends the Textview class with specific font style as follows. [1]: http://stackoverflow.com/questions/6926263/add-custom-font-for-complete-android-application – Senthil Mg Sep 27 '12 at 05:57

2 Answers2

1

One thing you can do is: Make custom textViews, by extending them, and then use them in your xml layouts. You will have to override setTypeface(Typeface tf, int style) method for that. You may want to have a look at this

Community
  • 1
  • 1
harshit
  • 3,788
  • 3
  • 31
  • 54
  • Thanks this is what i am doing. Is it possible that i can add the attributes from XML. I have a class that extends EditText. Now from the XML i want add a new attribute, say myfontFace="arial" and in the class i want to read the value of the xml, is that even possible. – AndroidDev Sep 27 '12 at 07:06
  • If you are talking about custom xmls then you might consider it keeping in res/raw and access it through `R` object. Else if you are talking about getting values from just xmls, put them into res/values/string.xml and you can access them through the `R` object – harshit Sep 27 '12 at 07:11
0

Try this

If from your asset folder

Typeface.createFromAsset(yourAssetManager, pathOfYourFontAsset);

If externally

Typeface.createFromFile(path)