android 设置字体样式
1. 全局设置字体样式
// api 'uk.co.chrisjenx:calligraphy:2.3.0'
Android Q及Android X 开发环境报错,需要升级
implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'
在Application初始化时进行设置
ViewPump.init(ViewPump.builder().addInterceptor(new CalligraphyInterceptor(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/SourceHanSerifCN-Regular.otf").setFontAttrId(R.attr.fontPath).build())).build());
设置完思源字体之后,APP整体行高太高了,需要修改字体,方法如下,也可以直接从网上下
Android思源字体显示行高很大解决_安卓 使用字体库后行高不可控-CSDN博客
2. WebView设置字体样式
1)WebView中加载字体:
<style>
@font-face {
font-family: 'SourceHanSerifCN';
src: url('file:///an