1、如果字体设置时sp单位、直接在BaseActivity 或者App 内重写getResources
如下:
override fun getResources(): Resources {
return super.getResources().apply {
configuration.fontScale=1f
updateConfiguration(configuration,displayMetrics)
}
}
以下是错误写法:
override fun getResources(): Resources {
return super.getResources().apply {
if (configuration.fontScale!=1f) {
configuration.fontScale=1f
updateConfiguration(configuration,displayMetrics)
}
}
}
不要对fontScale进行判断!切记
本文探讨了在Android开发中如何统一字体大小,重点指出在重写`getResources()`方法时,应直接将`configuration.fontScale`设置为1f,而避免进行条件判断。错误的写法可能导致字体缩放功能失效,正确的做法能确保全局字体一致且不受用户设置影响。
3004





