应该使用“sp";而不是“dp"对于文本大小 [英] Should use "sp" instead of "dp" for text sizes
问题描述
当我使用时
android:textSizes="20dp"
在我的 textView
的 XML 中,我收到一条警告应该使用 "sp"
而不是 "dp"
文本大小."
为什么不应该使用dp"?什么是正确的方法?如何在不同的显示器上实现相同的文本大小?
您应该始终使用 SP 作为字体,因为它尊重用户偏好.
更改设备文本设置(设置 -> 显示 -> 字体大小)
现在重新打开应用程序并重新查看文本,您会看到使用 SP 的文本与 DP 的高度不同.
When I use
android:textSizes="20dp"
in my XML for a textView
, I got a warning "Should use "sp"
instead of "dp"
for text sizes."
Why should "dp" not be used? What is the correct approach? How can I achieve same textsizes on different displays?
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.
这篇关于应该使用“sp";而不是“dp"对于文本大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!