將字體包放到assets文件目錄下掺冠,然后沉馆,取得路徑,將下面方法在BaseActivity中調(diào)用
private void shareTTF () {
String path = FileStorage.getInstance().getTtfDir() + File.separator + "2017_6_15_b68492fb3a975119.ttf";
File file = new File(path);
if(file.exists()) {
Typeface typeface = Typeface.createFromFile(file);
LayoutInflaterCompat.setFactory2(LayoutInflater.from(this),
new LayoutInflater.Factory2() {
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
return null;
}
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
AppCompatDelegate delegate = getDelegate();
View view = delegate.createView(parent, name, context, attrs);
if (view != null && view instanceof TextView) {
((TextView) view).setTypeface(typeface);
}
if (view != null && view instanceof EditText) {
((EditText) view).setTypeface(typeface);
}
if (view != null && view instanceof Button) {
((Button) view).setTypeface(typeface);
}
return view;
}
});
}
}