Why is it recommended to use "sp" instead of "dp" in text sizes?

6

Given that when we use the drive sp in TextView a warning always appears like this:

  

Should use "sp" instead of "dp" for text sizes

This SOpt response shows exactly the difference between units of measure: Doubt over px, dp, dip and sp on Android ?

sp

  

Scale-independent Pixels - Same as dp, but also consider the size   source that the user is using. It is recommended that you use this   unit when specifying the size of a font, so that it is   automatically adjusted according to the user's screen preferences.

dip ou dp

  

Density-independent Pixels - This unit is relative to the resolution of the   screen. For example if the screen resolution is 160 dpi, it means that   one dp represents 1 pixel in a total of 160. USE: I advise instead   to use px always use dp.

The question of the recommendation is in relation to the size that the user defines his font in ACCESSIBILITY in the device settings? Why the recommendation? Why is it recommended to use "sp" instead of "dp" in text sizes?

    
asked by anonymous 21.09.2016 / 20:04

1 answer

5

The recommendation is based on the assumption that when you change the text size in accessibility settings, you expect it to be passed on to all texts in all applications.

For this to happen, the text font size must be set with the unit sp .

The size of the text will not only fit the pixel density of the screen but also take into account the definition chosen in the Accessibility options.

    
21.09.2016 / 20:29