Android TextView文字使用字体的3种方法

Android给文字添加字体效果有3种方法:

1.直接在xml布局里面添加

先将字体文件复制到该位置

Android TextView文字使用字体的3种方法

 然后在xml中引用该文件

Android TextView文字使用字体的3种方法

2.在activity里面设置(1)

 先将字体文件复制到该位置

Android TextView文字使用字体的3种方法

然后在activity里面设置该字体

Typeface tfRegular = ResourcesCompat.getFont(mContext, R.font.simsun);//初始化字体
tv_title_first.setTypeface(tfRegular);

 3.在activity里面设置(2)

先将字体文件复制到该位置

Android TextView文字使用字体的3种方法

然后在activity里面设置该字体

Typeface tfRegular = Typeface.createFromAsset(mContext.getAssets(), "font/simsun.ttf");//初始化字体
tv_title_first.setTypeface(tfRegular);

 

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/b9837edfab.html