1

I have created a TextView library project where I have used a custom font. I have to create this library because this TextView will use in other three project as well. I found that assets/fonts folder is not supported by android library project. If I use this way it gives me error message

native typeface cannot be made at android.graphics.Typeface

Is there any workaround here to solve this issue. Other way, I have to use duplicate view in three different app. And also the sample code I am using to get font from library assets folder.

 public static Typeface getFont(Context c, String fontName) {
        synchronized (fonts) {
            if (!fonts.containsKey(fontName)) {
                Typeface t = Typeface.createFromAsset(
                        c.getAssets(), "fonts" + File.separator + fontName);
                fonts.put(fontName, t);
            }
            return fonts.get(fontName);
        }
    }
androidcodehunter
  • 21,567
  • 19
  • 47
  • 70

3 Answers3

0

infect you can do lot of things .one of easiest solution is following

you can write a function that copy paste font in some sd card folder and for sure it will be static . now you can create type from that path

createFromFile(String path)

http://developer.android.com/reference/android/graphics/Typeface.html

0

To use different Fonts in my project I have use font Library. Just add this library in gradle.

dependencies {
    compile 'com.vstechlab.easyfonts:easyfonts:1.0.0'
}

Use of this library is very easy. I have use reference https://android-arsenal.com/details/1/2044

Khyati Vara
  • 1,042
  • 13
  • 22
-1

create fonts directory in your assets folder and set your font with ttf format in the font directory. then call font by this code:

Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/font.ttf");
textViewName.setTypeface(tf);

your font must be here :

assets>fonts>font.ttf

rockstar
  • 587
  • 4
  • 22
Omid Zamani
  • 414
  • 1
  • 3
  • 15