app中替换字体,两种单位,页面和单个view
使用Calligraphy,简洁又方便
1、页面替换
(1)导入依赖
dependencies {
compile 'uk.co.chrisjenx:calligraphy:2.3.0'
}
(2)全局初始化(注意:只有需要在activity里使用才进行设置,单个view可以直接在布局里修改,不需要这一步)
//在application中加入
@Override
public void onCreate() {
super.onCreate();
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
//....
}
(3)给对应修改的activity里替换context
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(