Is there a way to prevent android system scaling of font size? Found one typescript solution, but can't make it work. Probably because i don't understand typescript good enough.
Asked
Active
Viewed 478 times
1
-
You may set your font size in px, may be something like `font-size: 12px` in CSS will prevent framework from applying scaled pixels. – Manoj Apr 07 '20 at 14:28
-
@Manoj Are you sure? Still scales in px and in dpi too – Andrew Tkachuk Apr 07 '20 at 14:57
1 Answers
2
Try this override in [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. The above one takes care of Label, Button etc.,

Manoj
- 21,753
- 3
- 20
- 41