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

Nativescript lock font-size, prevent system scaling

有没有办法阻止android系统缩放字体大小?找到了一种打字稿解决方案,但无法使其发挥作用。可能是因为我不太了解打字稿。

在 [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);
        }
    }
};

注意:如果您在项目中使用 TabView、HtmlView 等并希望禁用缩放,您可能必须对它们执行相同的操作。上面一个负责标签,按钮等,

Playground Sample