Android代码设置字体,两个存放资源方式

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);

你可能感兴趣的:(Android代码设置字体,两个存放资源方式)