Android代码设置字体,两个存放资源方式
2021-03-17 本文已影响0人
wenju
1.res中font目录
TextView txtNormal = (TextView) findViewById(R.id.txt_helvetica);
Typeface typeface = ResourcesCompat.getFont(this, R.font.test_ttf);
txtNormal.setTypeface(typeface);
2.Assets及fonts目录
TextView txtNormal = (TextView) findViewById(R.id.txt_helvetica);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/test_ttf.ttf");
txtNormal.setTypeface(typeface);