美文网首页
Android代码设置字体,两个存放资源方式

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

作者: wenju | 来源:发表于2021-03-17 14:53 被阅读0次

    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代码设置字体,两个存放资源方式

          本文链接:https://www.haomeiwen.com/subject/tdcecltx.html