应该使用"sp"而不是"dp"用于文字大小 [英] Should use "sp" instead of "dp" for text sizes

查看:346
本文介绍了应该使用"sp"而不是"dp"用于文字大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

android:textSizes="20dp" 

的XML中,

出现警告:对于文本大小,应使用"sp"而不是"dp"".

为什么不应该使用"dp"?正确的方法是什么?如何在不同的显示器上获得相同的文本大小?

Why should "dp" not be used? What is the correct approach? How can I achieve same textsizes on different displays?

推荐答案

您应该始终对字体使用SP,因为它会尊重用户的偏好. 以下是示例 让我们借助示例来了解它-

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 -

带有SP和DP的文本

更改设备文本设置(设置->显示->字体大小)

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

现在重新打开应用程序并查看文本,您将看到使用SP的文本与DP的高度不同.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆