我一直在使用Jake Wharton的ViewPagerIndicator,目前正尝试在其中一个片段上实现自定义字体。我尝试使用以下代码:
TextView txt = (TextView) findViewById(R.id.Zipcode);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/customfont.ttf");
txt.setTypeface(font);
在主活动的onCreate
中,logcat显示空指针异常,并偶尔显示typeface cannot be made
。我还尝试在片段的onCreate
和onCreateView
中设置字体,但是在片段范围内无法使用findViewById
和getAssests()
方法。我很难确定字体是否是问题所在,或者我尝试设置字体的位置是否有问题。
customfont.ttf
是否在assets/fonts/
目录下? - Kevin Coppock