Android|Android 全局设置字体

说到这,我估计你心理已经有全新的解决方案了,那就是利用setFactory,相关代码如下(在BaseActivity中):

publicstaticTypeface typeface;
@Override
protected void onCreate(Bundle savedInstanceState){
if(typeface ==null)
{
typeface = Typeface.createFromAsset(getAssets(),"hwxk.ttf");
}
LayoutInflaterCompat.setFactory(LayoutInflater.from(this),newLayoutInflaterFactory(){
@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&& (viewinstanceofTextView))
{((TextView) view).setTypeface(typeface);
}
return view;
}});
super.onCreate(savedInstanceState);
【Android|Android 全局设置字体】setContentView(R.layout.activity_main); }

    推荐阅读