Should use “sp” instead of “dp” for text sizes

前端 未结 4 1992
清酒与你
清酒与你 2020-11-30 07:15

When I use

android:textSizes=\"20dp\" 

in my XML for a textView, I got a warning \"Should use \"sp\" instead of <

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 08:05

    You should always use SP for fonts as it respects the user preferences. Here is an example Lets understand it with the help of an example -

    Text with SP and DP

    Change the device text setting (Settings -> Display -> Font Size)

    Now reopen the app and relook at the texts, You will see that the text which was using SP has different height than DP.

提交回复
热议问题