设置整个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;
                         }
                     });
         }
    }

你可能感兴趣的:(设置整个app的字体)