Search code examples
androidandroid-tvleanback

SP vs DP in Android TV


I know what is the difference between SD and DP in Android development and it makes perfect sense ... except for Android TV.

It seems wrong that the fonts would be smaller on a bigger TV screen. Why? Because typically having bigger TV means that the user will be sitting much further from it. So in my opinion fonts should scale proportionally to the layout.

I'm looking for a confirmation from somebody else that using DPs in Android TV makes perfect sense and I can ignore all Warning: Should use "sp" instead of "dp" for text sizes [SpUsage] warnings from Lint tool.


Solution

  • sp exists on both Android mobile and TV so that people can change their font size as an accessibility option in their device's settings. dp and sp automatically scale with the pixel density, but sp is impacted by the font settings on the device.

    So if a person using the TV app thinks the fonts on their TV are too small, they can change the setting and it will make the font larger everywhere for every app. Using dp to define text is essentially turning off the ability for the text in your app to respond to this font setting that the user has selected. This is why it is recommended to use sp instead of dp for text.

    For more info, check out this SO post