简体   繁体   English

Nativescript 锁定字体大小,防止系统缩放

[英]Nativescript lock font-size, prevent system scaling

Is there a way to prevent android system scaling of font size?有没有办法防止 android 系统缩放字体大小? Found one typescript solution, but can't make it work.找到一个 typescript 解决方案,但无法使其工作。 Probably because i don't understand typescript good enough.可能是因为我不太了解 typescript 不够好。

Try this override in [app|main].[js|ts],在 [app|main].[js|ts] 中尝试此覆盖,

import { layout } from "tns-core-modules/utils/utils";
import { fontSizeProperty, TextBase } from "tns-core-modules/ui/text-base";

TextBase.prototype[fontSizeProperty.setNative] = function (value) {
    if (!this.formattedText || (typeof value !== "number")) {
        if (typeof value === "number") {
            this.nativeTextViewProtected.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, layout.toDevicePixels(value));
        } else {
            this.nativeTextViewProtected.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
        }
    }
};

Note: You may have to do the same on TabView, HtmlView etc., if you are using them in your project and want to disable scaling.注意:如果您在项目中使用 TabView、HtmlView 等并希望禁用缩放,您可能必须在 TabView、HtmlView 等上执行相同操作。 The above one takes care of Label, Button etc.,上面一个照顾Label,Button等,

Playground Sample 游乐场样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM