设置整个app的字体

将字体包放到assets文件目录下,然后,取得路径,将下面方法在BaseActivity中调用

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;
                         }
                     });
         }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容