1

I have:

  • one Main App
  • one Android Library Project with a Fonts in it in "assets/fonts/Old_English.ttf
  • The Main App references the Android Library Project and it works fine except the following:

I would like the use the shared asset resource, but I don't know how to do. Can someone help ?

Typeface.createFromAsset(getAssets(), "fonts/Old English.ttf")
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
  • How about creating a class with static method in your library which can access the assets of that library? I am not sure about direct solution, but till you find any direct solution, you can use this. In general when you import library, all of its resources are also imported, not sure about assets. – Mohammed Atif Sep 30 '16 at 12:59
  • Thats a good idea. Still I leave this question, because I think there will probably a direct solution. But yours is also a good one I think. – mcfly soft Sep 30 '16 at 13:20
  • The suggestion above does not work, because effectively we have no 2 parts of code. getting the typeface with a static method in the library project means getting the typeface from the local app at runtime. The Project Library is just merged to the actual app. Its not seperated. (Sorry my bad english) – mcfly soft Oct 01 '16 at 07:09
  • i have done something similar with drawables. it worked perfectly fine. so gave a suggestion for typeface. as already mentioned. its just a suggestion since i am not sure about its working. but will definitely try to find an answer since this question is interesting. – Mohammed Atif Oct 01 '16 at 09:34
  • drawable works fine, but assets with fonsts not. Thanks. – mcfly soft Oct 02 '16 at 23:31

2 Answers2

0

These might work:

  1. Storing and accessing assets.

library structure

MyLibProject/src/main/assets/Old_English.ttf

Project Reference

Typeface.createFromAsset("file:///android_asset/Old_English.ttf");

The solution is as per the link mentioned. I didn't try its working. Please comment if it works or not.

Community
  • 1
  • 1
Mohammed Atif
  • 4,383
  • 7
  • 28
  • 57
0

Make sure that you store your fonts according to the following structure :

enter image description here

Now use the following line :

   Typeface typeface=Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Old_English.ttf");
Ayan
  • 8,192
  • 4
  • 46
  • 51
  • Where is the Android Project Library ? I did not ask how to use the ttf in your only one project, I would like to use the ttf from the Android Library Project. What you described is just how to do this in one Android Project, which is clear to me. – mcfly soft Oct 08 '16 at 14:12