“RuntimeException: native typeface cannot be made” when loading font

后端 未结 9 1723
生来不讨喜
生来不讨喜 2020-12-05 09:35

I am attempting to use a custom font for a TextView on Android, following the guide here. Using the same font, same code, same everything, I get this in adb logcat:

9条回答
  •  囚心锁ツ
    2020-12-05 10:00

    Android does support OTF files for Typefaces, if you're facing this problem, make sure that you're setting the right path for the font.put font into folder fonts inside assets folder and create the typeface as below :

    Typeface typeface = Typeface.createFromAsset(getAssets(), "font/StencilStd.otf");
    TextView text = (TextView) findViewById(R.id.textView);
    text.setTypeface(typeface);
    

提交回复
热议问题