设备设置独立的字体大小 [英] Device settings independent font size

查看:151
本文介绍了设备设置独立的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发我的应用程序,我意识到,如果有人从正常更改设备字体大小,我的应用程序的字体大小改变也是一样,它破坏了一些,我设计的视觉效果。所以我想问是否有办法解决的文字,从设备的设置大小无关?

While developing my app I realised if someone changes device font size from normal, my application font sizes change too and it destroys some of the visuals I designed. So I wanted to ask if there is a way to fix text sizes independent from device's settings?

感谢

推荐答案

如果你想完全无视用户的字体大小preferences,然后用 DP 而不是 SP 的字体大小。棉绒会抱怨 DP 的使用(这是正确的,因为你有可能导致给用户带来不便,并有可能使您的应用程序无法使用为视障的),但你应该没有面对任何运行时的问题。

If you want to completely ignore user's font size preferences, then use dp instead of sp for font sizes. The lint will complain about the dp usage (and rightly so, because you are potentially causing inconvenience to the user and possibly rendering your app unusable for visually impaired ones), but you should not face any runtime issues.

如果你只是想忽略运行时的字体大小的变化,使用 fontScale

If you just want to ignore runtime font size changes, use "fontScale":

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    ... >
    <activity android:name=".MyActivity"
        android:configChanges="fontScale">
        ...
    </activity>
</application>

这篇关于设备设置独立的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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