Android TextSize文字字体大小设置

使用sp作为字体大小单位,会随着系统的字体大小改变而dp作为单位则不会
这里写图片描述

系统字体由标准改为特大后显示效果:
这里写图片描述

总结:
长度宽度的数值要使用dp作为单位放入dimens.xml文件中
字体大小的数值要使用sp作为单位,也放入dimens.xml文件中
关于sp, 文档 的描述为:

Scale-independent Pixels – This is like the dp unit, but it is also scaled by the user’s font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user’s preference.
意思为
sp除了受屏幕密度影响外,还受到用户的字体大小影响
通常情况下,建议使用sp来跟随用户字体大小设置

通常情况下,建议使用sp作为字体的单位,除非一些特殊的情况,不想跟随系统字体变化的,可以使用dp.

猜你喜欢

转载自blog.csdn.net/pillar1066527881/article/details/80001650
今日推荐