鸿蒙中调整应用内文字大小

1、ui

       Stack() {Row() {ForEach([1, 2, 3, 4], (item: number) => {Text().width(3).height(20).backgroundColor(Color.Black).margin(item === 2 ? { left: 8 } : item === 3 ? { left: 7 } : { left: 0 })})}.width('97%').justifyContent(FlexAlign.SpaceBetween).padding({ right: 2 })Slider({value: this.changeFontSize === CommonConstants.SET_SIZE_HUGE? CommonConstants.SET_SLIDER_MAX : this.changeFontSize === 16 ? this.changeFontSize = 16.700000762939453 :this.changeFontSize === 19 ? this.changeFontSize = 19.399999618530273 : this.changeFontSize,min: CommonConstants.SET_SLIDER_MIN,max: CommonConstants.SET_SLIDER_MAX,step: CommonConstants.SET_SLIDER_STEP,style: SliderStyle.OutSet}).blockColor(Color.White).trackColor(Color.Black).selectedColor(Color.Black).showSteps(true).onChange(async (value: number) => {if (this.changeFontSize === 0) {this.changeFontSize = await PreferencesUtil.getChangeFontSize();return;}this.changeFontSize =(Math.floor(value) === CommonConstants.SET_SLIDER_MAX ? CommonConstants.SET_SIZE_HUGE :Math.floor(value));PreferencesUtil.saveChangeFontSize(this.changeFontSize);})}

2、工具类

        1.

/** Copyright (c) 2022 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*//*** Common constants for all features.*/
export default class CommonConstants {/*** Small font size.*/static readonly SET_SIZE_SMALL: number = 14;/*** Normal font size.*/static readonly SET_SIZE_NORMAL: number = 16.7;/*** Large font size.*/static readonly SET_SIZE_LARGE: number = 19.4;/*** Extra large font size.*/static readonly SET_SIZE_EXTRA_LARGE: number = 20;/*** Huge font size.*/static readonly SET_SIZE_HUGE: number = 24;/*** Slider min value.*/static readonly SET_SLIDER_MIN: number = 14;/*** Slider max value.*/static readonly SET_SLIDER_MAX: number = 22;/*** Slider step length.*/static readonly SET_SLIDER_STEP: number = 2.7;/*** The setting list display index.*/static readonly DISPLAY_INDEX: number = 0;/*** The setting list voice index.*/static readonly VOICE_INDEX: number = 1;/*** The setting list slice start index.*/static readonly START_INDEX: number = 2;/*** The setting list slice font index.*/static readonly SET_FONT_INDEX: number = 3;/*** The setting list slice end index.*/static readonly END_INDEX: number = 6;/*** The set font size url.*/static readonly SET_URL: string = 'pages/SetFontSizePage';
}

        2.

/** Copyright (c) 2023 Huawei Device Co., Ltd.* Licensed under the Apache License,Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/export class GlobalContext {private constructor() { }private static instance: GlobalContext;private _objects = new Map<string, Object>();public static getContext(): GlobalContext {if (!GlobalContext.instance) {GlobalContext.instance = new GlobalContext();}return GlobalContext.instance;}getObject(value: string): Object | undefined {return this._objects.get(value);}setObject(key: string, objectClass: Object): void {this._objects.set(key, objectClass);}
}

        3.

/** Copyright (c) 2022 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/import { preferences } from '@kit.ArkData';
import { GlobalContext } from '../utils/GlobalContext';const TAG = '[PreferencesUtil]';
const PREFERENCES_NAME = 'myPreferences';
const KEY_APP_FONT_SIZE = 'appFontSize';/*** The PreferencesUtil provides preferences of create, save and query.*/
export class PreferencesUtil {createFontPreferences(context: Context) {let fontPreferences: Function = (() => {let preference: Promise<preferences.Preferences> = preferences.getPreferences(context, PREFERENCES_NAME);return preference;});GlobalContext.getContext().setObject('getFontPreferences', fontPreferences);}saveDefaultFontSize(fontSize: number) {let getFontPreferences: Function = GlobalContext.getContext().getObject('getFontPreferences') as Function;getFontPreferences().then((preferences: preferences.Preferences) => {preferences.has(KEY_APP_FONT_SIZE).then(async (isExist: boolean) => {if (!isExist) {await preferences.put(KEY_APP_FONT_SIZE, fontSize);preferences.flush();}}).catch((err: Error) => {});}).catch((err: Error) => {});}saveChangeFontSize(fontSize: number) {let getFontPreferences: Function = GlobalContext.getContext().getObject('getFontPreferences') as Function;getFontPreferences().then(async (preferences: preferences.Preferences) => {await preferences.put(KEY_APP_FONT_SIZE, fontSize);preferences.flush();}).catch((err: Error) => {});}async getChangeFontSize() {let fontSize: number = 0;let getFontPreferences: Function = GlobalContext.getContext().getObject('getFontPreferences') as Function;// const preferences: dataPreferences.Preferences = await getFontPreferences();fontSize = await (await getFontPreferences()).get(KEY_APP_FONT_SIZE, fontSize);return fontSize;}async deleteChangeFontSize() {let getFontPreferences: Function = GlobalContext.getContext().getObject('getFontPreferences') as Function;const preferences: preferences.Preferences = await getFontPreferences();let deleteValue = preferences.delete(KEY_APP_FONT_SIZE);deleteValue.then(() => {}).catch((err: Error) => {});}
}export default new PreferencesUtil();

4.

/** Copyright (c) 2022 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*//*** Style constants for all features.*/
export default class StyleConstants {/*** The head aspect ratio.*/static readonly HEAD_ASPECT_RATIO: number = 1;/*** Weight to fill.*/static readonly WEIGHT_FULL: number = 1;/*** Minimum height of two lines of text.*/static readonly DOUBLE_ROW_MIN: number = 28;/*** Unit of fp.*/static readonly UNIT_FP: string = 'fp';/*** Full the width.*/static readonly FULL_WIDTH: string = '100%';/*** Full the height.*/static readonly FULL_HEIGHT: string = '100%';/*** The percentage of 7.2.*/static readonly TITLE_BAR_HEIGHT_PERCENT: string = '7.2%';/*** The percentage of 93.3.*/static readonly BLOCK_WIDTH_PERCENT: string = '93.3%';/*** The percentage of 0.5.*/static readonly BLOCK_TOP_MARGIN_FIRST_PERCENT: string = '0.5%';/*** The percentage of 1.5.*/static readonly BLOCK_TOP_MARGIN_SECOND_PERCENT: string = '1.5%';/*** The percentage of 23.8.*/static readonly DIVIDER_END_MARGIN_PERCENT: string = '23.8%';/*** The percentage of 6.7.*/static readonly HEAD_RIGHT_PERCENT: string = '6.7%';/*** The percentage of 2.2.*/static readonly HEAD_LEFT_PERCENT: string = '2.2%';/*** The percentage of 64.4.*/static readonly MAX_CHAT_WIDTH_PERCENT: string = '64.4%';/*** The percentage of 3.1.*/static readonly CHAT_TOP_MARGIN_PERCENT: string = '3.1%';/*** The percentage of 6.5.*/static readonly SLIDER_LAYOUT_LEFT_PERCENT: string = '6.5%';/*** The percentage of 3.2.*/static readonly SLIDER_LAYOUT_TOP_PERCENT: string = '3.2%';/*** The percentage of 8.9.*/static readonly SET_CHAT_HEAD_SIZE_PERCENT: string = '8.9%';/*** The percentage of 12.5.*/static readonly A_WIDTH_PERCENT: string = '12.5%';/*** The percentage of 75.*/static readonly SLIDER_WIDTH_PERCENT: string = '75%';/*** The percentage of 3.3.*/static readonly SLIDER_HORIZONTAL_MARGIN_PERCENT: string = '3.3%';/*** The percentage of 1.*/static readonly SLIDER_TOP_MARGIN_PERCENT: string = '1%';/*** The percentage of 6.2.*/static readonly SLIDER_BOTTOM_MARGIN_PERCENT: string = '6.2%';
}

3、使用

  @State changeFontSize: number = CommonConstants.SET_SIZE_NORMAL;onPageShow() {PreferencesUtil.getChangeFontSize().then((value) => {this.changeFontSize = value;});}Text('字体大小').fontSize(this.changeFontSize)

4.配置文件(api13,不需要配置,api13以下需要)

详情文档中心

AppScope/resources/base/profile/configuration.json中

{"configuration": {"fontSizeScale": "nonFollowSystem"}
}

app.json5中

    "configuration": "$profile:configuration",

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/892361.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Docker compose 使用 --force-recreate --no-recreate 控制重启容器时的行为【后续】

前情&#xff1a;上一篇实际是让AI工具帮我总结了一下讨论的内容&#xff0c;这里把讨论的过程贴出来&#xff0c;这个讨论是为解决实际问题 前文https://blog.csdn.net/wgdzg/article/details/145039446 问题说明&#xff1a; 我使用 docker compose 管理我的容器&#xff0…

SAP SD学习笔记27 - 贩卖契约(框架协议)2 - 基本契约 - 金额契约(价值合同)

上一章讲了贩卖契约&#xff08;框架协议&#xff09;的概要&#xff0c;以及贩卖契约中最为常用的 基本契约 - 数量契约。 SAP SD学习笔记26 - 贩卖契约(框架协议)的概要&#xff0c;基本契约 - 数量契约-CSDN博客 本章继续讲SAP中的内容&#xff1a; - 基本契约 - 金额契约…

【面试题】技术场景 7、定位系统瓶颈

系统瓶颈定位方法总述 面试官询问如何快速定位系统瓶颈&#xff0c;旨在考察线上调试经验。主要方法包括&#xff1a; 压测&#xff1a;在项目上线前找出系统瓶颈并修复。监控工具或链路追踪工具&#xff1a;项目上线后用于实时监控或评测找瓶颈。Arthas&#xff08;原阿尔萨…

在Jmeter中跨线程组传递变量(token)--设置全局变量

参考资料&#xff1a; Jmeter跨线程组传递参数(token)_jmeter获取token传递给下一个线程组详解-CSDN博客 最近工作中遇到一个问题&#xff0c;就是如何跨线程组传递变量&#xff0c;比如token,后来找到一些资料解决了该问题&#xff0c;目前有两种方式都可以解决&#xff0c;我…

QT 常用控件的常用方法

QRadioButton、QCheckBox 常用函数&#xff1a; text(): 用于获取单选按钮的文本标签。 setText(const QString &text): 用于设置单选按钮的文本标签。 isChecked(): 用于检查单选按钮是否被选中。 setChecked(bool checked): 用于设置单选按钮是否被选中。 setIcon(c…

Element-UI:如何实现表格组件el-table多选场景下根据数据对某一行进行禁止被选中?

如何实现表格组件el-table多选场景下根据数据对某一行进行禁止被选中&#xff1f; 在使用 Element UI 的 Table 组件时&#xff0c;如果你想要禁用某一行的选中&#xff08;特别是在多选模式下&#xff09;&#xff0c;可以通过自定义行的 selectable 属性来实现。selectable …

rhcsa练习(3)

1 、创建文件命令练习&#xff1a; &#xff08; 1 &#xff09; 在 / 目录下创建一个临时目录 test &#xff1b; mkdir /test &#xff08; 2 &#xff09;在临时目录 test 下创建五个文件&#xff0c;文件名分别为 passwd &#xff0c; group &#xff0c; bashrc &#x…

uc/os-II 原理及应用(八) 系统裁减以及移植到51单片机上

两个习题 先了解下CPU上函数调用的过程: 一个程序取得函数地址&#xff0c;先保护现场将局部变量及参数压栈&#xff0c;再将调用函数的参数压栈&#xff0c;然后跳转到函数位置&#xff0c;将参数出栈&#xff0c;执行代码&#xff0c;结束后返回到调用位置&#xff0c;再怖复…

高等数学学习笔记 ☞ 洛必达法则与泰勒公式

1. 洛必达法则 1. 型与型未定式&#xff08;洛必达法则&#xff09; &#xff08;1&#xff09;型&#xff1a;若函数同时满足以下条件&#xff1a; &#xff08;2&#xff09;型&#xff1a;若函数同时满足以下条件&#xff1a; ①&#xff1a;当时&…

什么样的人适合从事FPGA开发的工作?

FPGA开发不仅要求扎实的技术基础&#xff0c;还非常看重团队合作、自信、沟通技巧以及细致入微的工作态度。从业者需具备面对复杂项目的自信&#xff0c;优秀的沟通能力以确保团队协作顺畅&#xff0c;严谨细心以应对精密的硬件设计&#xff0c;以及强烈的责任心来驱动每一个开…

【LeetCode】力扣刷题热题100道(26-30题)附源码 轮转数组 乘积 矩阵 螺旋矩阵 旋转图像(C++)

目录 1.轮转数组 2.除自身以外数组的乘积 3.矩阵置零 4.螺旋矩阵 5.旋转图像 1.轮转数组 给定一个整数数组 nums&#xff0c;将数组中的元素向右轮转 k 个位置&#xff0c;其中 k 是非负数。 class Solution { public:void rotate(vector<int>& nums, int k) …

JAVA 使用apache poi实现EXCEL文件的输出;apache poi实现标题行的第一个字符为红色;EXCEL设置某几个字符为别的颜色

设置输出文件的列宽&#xff0c;防止文件过于丑陋 Sheet sheet workbook.createSheet(FileConstants.ERROR_FILE_SHEET_NAME); sheet.setColumnWidth(0, 40 * 256); sheet.setColumnWidth(1, 20 * 256); sheet.setColumnWidth(2, 20 * 256); sheet.setColumnWidth(3, 20 * 25…

卷积神经网络CNN——卷积层、池化层、全连接层

参考这篇文章,讲的很详细: 卷积神经网络CNN——卷积层、池化层、全连接层_卷积层,池化层,全连接层-CSDN博客 原文链接:https://blog.csdn.net/qq_59702185/article/details/143744365 学习目标 了解卷积神经网络的构成 知道卷积的原理以及计算公式 了解池化的作用以及计算…

怎么抓取ios 移动app的https请求?

怎么抓取IOS应用程序里面的https&#xff1f; 这个涉及到2个问题 1.电脑怎么抓到IOS手机流量&#xff1f; 2.HTTPS怎么解密&#xff1f; 部分app可以使用代理抓包的方式&#xff0c;但是正式点的app用代理抓包是抓不到的&#xff0c;例如pin检测&#xff0c;证书双向校验等…

身份鉴权(PHP)(小迪网络安全笔记~

免责声明&#xff1a;本文章仅用于交流学习&#xff0c;因文章内容而产生的任何违法&未授权行为&#xff0c;与文章作者无关&#xff01;&#xff01;&#xff01; 附&#xff1a;完整笔记目录~ ps&#xff1a;本人小白&#xff0c;笔记均在个人理解基础上整理&#xff0c;…

自定义音频播放样式结合Howler.js

滑动式滚动条 不使用audio默认样式 自定义音频播放样式 当前时间 开始时间 结束时间 可播放可暂停 滚动条可拖动进行同步 具体样式可调整npm install howler --save<template><div class"audio-player"><div v-if"isLoading" class"l…

LLM prompt提示构造案例:语音回复内容;o1思维链

1、语音回复内容 目的&#xff1a; 语音聊天助手的prompt&#xff0c;让大模型来引导聊天内容&#xff0c;简短和友好&#xff0c;从而文字转语音时候也比较高效。 ## 角色设定与交互规则 ### 基本角色 你是用户的好朋友. 你的回答将通过逼真的文字转语音技术阅读. ### 回答规则…

AES 与 SM4 加密算法:深度解析与对比

&#x1f9d1; 博主简介&#xff1a;CSDN博客专家&#xff0c;历代文学网&#xff08;PC端可以访问&#xff1a;https://literature.sinhy.com/#/literature?__c1000&#xff0c;移动端可微信小程序搜索“历代文学”&#xff09;总架构师&#xff0c;15年工作经验&#xff0c;…

Sentinel服务保护 + Seata分布式事务

服务保护 【雪崩问题】微服务调用链路中某个服务&#xff0c;引起整个链路中所有微服务都不可用。 【原因】&#xff1a; 微服务相互调用&#xff0c;服务提供者出现故障。服务调用这没有做好异常处理&#xff0c;导致自身故障。调用链中所有服务级联失败&#xff0c;导致整个…

ssh2-sftp-client uploadDir Upload error: getLocalStatus: Bad path: ./public

报错解释 这个错误表明在使用 ssh2-sftp-client 这个Node.js库进行目录上传时遇到了问题。具体来说&#xff0c;是指定的本地路径&#xff08;./public&#xff09;不正确或者不存在。 解决方法&#xff1a; 确认当前工作目录&#xff1a;确保你在执行上传操作时的当前工作目…