【问题标题】:Nativescript lock font-size, prevent system scalingNativescript 锁定字体大小,防止系统缩放
【发布时间】:2020-07-19 16:04:27
【问题描述】:

有没有办法防止android系统缩放字体大小?找到了一种打字稿解决方案,但无法使其工作。可能是因为我对打字稿的理解不够好。

【问题讨论】:

  • 您可以以像素为单位设置字体大小,在 CSS 中可能类似于 font-size: 12px 会阻止框架应用缩放像素。
  • @Manoj 你确定吗?仍然以 px 和 dpi 为单位进行缩放

标签: android nativescript font-size nativescript-vue


【解决方案1】:

在 [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 等并希望禁用缩放,您可能必须对它们执行相同操作。上面一个负责Label,Button等,

Playground Sample

【讨论】:

    猜你喜欢
    • 2023-02-14
    • 2015-11-02
    • 1970-01-01
    • 2017-10-01
    • 2018-05-10
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多