原创作品,转载请注明:Android开发之设置APP全局字体
今天带来一篇和字体有关的:设置APP全局字体。
在开发的过程中可能有需求是使用某种要求的字体而不是默认字体,在使用少的情况下,我们可以选择直接设置或者自定义View,用到的时候使用自定义的TextView。如:
public class CustomFontTextView extends TextView{
public CustomFontTextView(Context context) {
this(context, null);
}
public CustomFontTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
//使用自定义的字体库
private void init(Context context){
AssetManager assetManager=context.getAssets();
Typeface typeface=Typeface.createFromAsset(assetManager, "font/huawenxihei.ttf");
setTypeface(typeface);
}
}