RuntimeException: native typeface cannot be made

前端 未结 3 1182
余生分开走
余生分开走 2020-12-20 13:26

I\'m trying to use a custom font on elements of a listview. So in my ListViewAdapter constructor I have:

private Context context;
private List         


        
相关标签:
3条回答
  • 2020-12-20 14:02

    OpenSans-Regular.ttf should be under fonts folder .

    folder structure should be like this :

    assets-> fonts ->OpenSans-Regular.ttf

    i think by mistake you have added under assets folder
    
    0 讨论(0)
  • 2020-12-20 14:08

    I do my fonts like this: (I declare them in my MainActivity)

    public static TypeFace FONT_HEADINGS;
    

    Then I set them up in onCreate()

    FONT_HEADINGS = Typeface.createFromAsset(this.getAssets(), "MyriadPro-Cond.otf");
    

    At this point, I can reference them throughout my app as:

    sampleTextView.setTypeFace(MainActivity.FONT_HEADINGS);
    

    Edit:

    "src/main/assests/fonts"

    the "assets" folder should not be under the "src" folder. It belongs in the at the same level as the src, res, etc.

    0 讨论(0)
  • 2020-12-20 14:10

    One problem that's overlooked (by Android Studio users) is that the "assets/" folder is NOT on the same level as "src/". It is INSIDE "src/main/"

    Because I didn't see this earlier, I spent two hours last night, and an hour this morning just trying to change the font in my navigation drawer.

    I believe this is the same reason why pixlUI and calligraphy libraries did not work for me.

    0 讨论(0)
提交回复
热议问题