当前位置: 首页 > news >正文

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

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",

相关文章:

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

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({ ri…...

计算机网络之---防火墙与入侵检测系统(IDS)

防火墙与入侵检测系统(IDS) 防火墙&#xff08;Firewall&#xff09; 和 入侵检测系统&#xff08;IDS, Intrusion Detection System&#xff09; 都是网络安全的关键组件&#xff0c;但它们的作用、功能和工作方式有所不同。 防火墙 防火墙是网络安全的一种设备或软件&#…...

KG-CoT:基于知识图谱的大语言模型问答的思维链提示

一些符号定义 知识图谱实体数量&#xff1a; n n n 知识图谱中关系类型数量&#xff1a; m m m 三元组矩阵&#xff1a; M ∈ { 0 , 1 } n n m \textbf{M} \in \{0, 1\}^{n \times n \times m} M∈{0,1}nnm&#xff0c; M i j k 1 M_{ij}^k 1 Mijk​1则说明实体 i i i和实…...

【JMeter】多接口关联

1. 同一线程组内,如何实现多接口关联 非加密的值 前置接口的返回单条数据使用Json提取器提取前置接口的返回多条数据使用Json提取器+逻辑控制器Loop Controller前置接口的返回多条数据使用Json提取器+逻辑控制器forEach加密的值 前置接口的返回值使用Beanshell后置提取器存储为…...

2020 年 12 月青少年软编等考 C 语言五级真题解析

目录 T1. 漫漫回国路思路分析T2. 装箱问题思路分析T3. 鸣人和佐助思路分析T4. 分成互质组思路分析T1. 漫漫回国路 2020 年 5 月,国际航班一票难求。一位在美国华盛顿的中国留学生,因为一些原因必须在本周内回到北京。现在已知各个机场之间的航班情况,求问他回不回得来(不考…...

前端实时显示当前在线人数的实现

实时显示当前在线人数的实现 本文档提供了在网页上实时显示当前在线人数的多种实现方法&#xff0c;包括使用 WebSocket 实现实时更新和轮询方式实现非实时更新。 方法一&#xff1a;使用 WebSocket 实现实时更新 服务器端设置 通过 Node.js 和 WebSocket 库&#xff08;如 …...

Linux第一个系统程序---进度条

进度条---命令行版本 回车换行 其实本质上回车和换行是不同概念&#xff0c;我们用一张图来简单的理解一下&#xff1a; 在计算机语言当中&#xff1a; 换行符&#xff1a;\n 回车符&#xff1a;\r \r\n&#xff1a;回车换行 这时候有人可能会有疑问&#xff1a;我在学习C…...

vscode 无法使用npm, cmd命令行窗口可以正常执行

解决方法&#xff1a; 执行命令获得命令的位置 get-command npm 得到如下 然后删除或者修改 npm.ps1文件 让其不能使用就行。然后重启vscode即可。 pnpm 同理即可 另外加速源 国内镜像源&#xff08;淘宝&#xff09;&#xff1a; npm config set registry https://regist…...

Leetcode 967 Numbers With Same Consecutive Differences

题意 给定n&#xff0c;代表整数的长度&#xff0c;给定k代表两个相邻数字之间的间隔。求所有的值构成的组合 题目链接 https://leetcode.com/problems/numbers-with-same-consecutive-differences/description/ 题解 dfs&#xff0c;有k位置要选&#xff0c;第一个位置我…...

node.js中实现token的生成与验证

Token&#xff08;令牌&#xff09;是一种用于在客户端和服务器之间安全传输信息的加密字符串。在Web开发中&#xff0c;Token常用于身份验证和授权&#xff0c;确保用户能够安全地访问受保护的资源。 作用与意义 身份验证&#xff1a;Token可以用来验证用户的身份&#xff0…...

[C++11]_[初级]_[工作线程如何监听主线程条件变量wait_for方法的使用]

场景 在开发多线程程序时&#xff0c;有时候需要启动一个线程来监听外部进程的执行情况&#xff0c;并且在指定时间如果还没运行结束就强制结束外部线程。那么C标准库有这种监听线程并能在超时时提示的方法吗&#xff1f; 说明 在C11的<condition_variable>里就可以用…...

Openstack持久存储-Swift,Cinder,Manila三者之间的区别

总结不易&#xff0c;给个三连吧&#xff01;&#xff01;&#xff01; 补充&#xff1a; 文件共享存储服务Manila 在OpenStack生态系统中&#xff0c;Cinder和Manila分别提供了两种不同类型的存储服务&#xff0c;类似于传统的SAN&#xff08;存储区域网络&#xff09;和NAS&…...

深度学习第三弹:python入门与线性表示代码

一、python入门 1.熟悉基础数据结构——整型数据&#xff0c;浮点型数据&#xff0c;列表&#xff0c;字典&#xff0c;字符串&#xff1b;了解列表及字典的切片&#xff0c;插入&#xff0c;删除操作。 list1 [1, 2, 3, 4, 5] for each in list1:print(each) print(list1[1…...

解决报错记录:TypeError: vars() argument must have __dict__ attribute

解决报错记录&#xff1a;manager_pyplot_show vars(manager_class).get(“pyplot_show“) TypeError: vars() argument must 1.问题引申 在pycharm中调用matplotlib函数批量绘制维度图时&#xff0c;抛出异常&#xff1a; manager_pyplot_show vars(manager_class).get(&…...

SpringBoot 原理篇(day14)

配置优先级 SpringBoot 中支持三种格式的配置文件&#xff1a; 配置文件优先级排名&#xff08;从高到低&#xff09;&#xff1a; properties 配置文件yml 配置文件yaml 配置文件 注意事项 虽然 springboot 支持多种格式配置文件&#xff0c;但是在项目开发时&#xff0c;推荐…...

Vscode辅助编码AI神器continue插件

案例效果 1、安装或者更新vscode 有些版本的vscode不支持continue,最好更新到最新版,也可以直接官网下载 https://code.visualstudio.com/Download 2、安装continue插件 搜索continue,还未安装的,右下脚有个Install,点击安装即可 <...

Type-C单口便携显示器-LDR6021

Type-C单口便携显示器是一种新兴的显示设备&#xff0c;它凭借其便携性、高性能和广泛的应用场景等优势&#xff0c;正在成为市场的新宠。以下是Type-C单口便携显示器的具体运用方式&#xff1a; 一、连接与传输 1. **设备连接**&#xff1a;Type-C单口便携显示器通过Type-C接…...

青少年编程与数学 02-006 前端开发框架VUE 19课题、内置组件

青少年编程与数学 02-006 前端开发框架VUE 19课题、内置组件 一、Transition<Transition> 组件基于 CSS 的过渡效果CSS 过渡 class为过渡效果命名CSS 的 transitionCSS 的 animation自定义过渡 class同时使用 transition 和 animation深层级过渡与显式过渡时长性能考量 J…...

腾讯云AI代码助手编程挑战赛 - 使用 JavaScript 构建一个简易日历

功能简介&#xff1a; 动态年份选择&#xff1a;用户可以通过下拉框选择从 2000 年到 2050 年的任意年份。全年日历生成&#xff1a;根据用户选择的年份&#xff0c;动态生成该年份的所有 12 个月份的日历。直观的 UI 设计&#xff1a;使用 CSS 美化日历外观&#xff0c;使日历…...

Xcode 正则表达式实现查找替换

在软件开发过程中&#xff0c;查找和替换文本是一项常见的任务。正则表达式&#xff08;Regular Expressions&#xff09;是一种强大的工具&#xff0c;可以帮助我们在复杂的文本中进行精确的匹配和替换。Xcode 作为一款流行的开发工具&#xff0c;提供了对正则表达式的支持。本…...

学习flv.js

前言 flv.js一款使用纯 JavaScript 编写的 HTML5 Flash 视频 (FLV) 播放器&#xff0c;无需 Flash&#xff01;&#xff01;&#xff01;flv.js 的工作原理是将 FLV 文件流转换为 ISO BMFF&#xff08;碎片 MP4&#xff09;片段&#xff0c;然后通过Media Source Extensions&l…...

FreePBX 17 on ubuntu24 with Asterisk 20

版本配置&#xff1a; FreePBX 17&#xff08;最新&#xff09; Asterisk 20&#xff08;最新Asterisk 22&#xff0c;但是FreePBX 17最新只支持Asterisk 21&#xff0c;但是21非LTS版本&#xff0c;所以选择Asterisk 20&#xff09; PHP 8.2 Maria DB (v10.11) Node J…...

【算法】算法大纲

这篇文章介绍计算机算法的各个思维模式。 包括 计数原理、数组、树型结构、链表递归栈、查找排序、管窥算法、图论、贪心法和动态规划、以及概率论:概率分治和机器学习。没有办法逐个说明,算法本身错综复杂,不同的算法对应着不同的实用场景,也需要根据具体情况设计与调整。…...

【MySQL】SQL菜鸟教程(一)

1.常见命令 1.1 总览 命令作用SELECT从数据库中提取数据UPDATE更新数据库中的数据DELETE从数据库中删除数据INSERT INTO向数据库中插入新数据CREATE DATABASE创建新数据库ALTER DATABASE修改数据库CREATE TABLE创建新表ALTER TABLE变更数据表DROP TABLE删除表CREATE INDEX创建…...

安装本地测试安装apache-doris

一、安装前规划 我的服务器是三台麒麟服务器,2台跑不起来,这是我本地的,内存分配的也不多。 fe192.168.1.13 主数据库端口9030访问 8Gbe192.168.1.13内存4G 硬盘50be192.168.1.14内存4G 硬盘50be192.168.1.12内存4G 硬盘5013同时安装的fe和be 。 原理:192.168.1.13 服…...

【Apache Paimon】-- 13 -- 利用 paimon-flink-action 同步 mysql 表数据

利用 Paimon Schema Evolution 核心特性同步变更的 mysql 表结构和数据 1、背景信息 在Paimon 诞生以前,若 mysql/pg 等数据源的表结构发生变化时,我们有几种处理方式 (1)人工通知(比如常规的使用邮件),然后运维人员手动同步到数据仓库中 (2)使用 flink 消费 DDL bi…...

IOS HTTPS代理抓包工具使用教程

打开抓包软件 在设备列表中选择要抓包的 设备&#xff0c;然后选择功能区域中的 HTTPS代理抓包。根据弹出的提示按照配置文件和设置手机代理。如果是本机则会自动配置&#xff0c;只需要按照提醒操作即可。 iOS 抓包准备 通过 USB 将 iOS 设备连接到电脑&#xff0c;设备需解…...

在 Ubuntu 22.04 上从 Wayland 切换到 X11的详细步骤

在 Ubuntu 22.04 上从 Wayland 切换到 X11&#xff0c;步骤其实很简单&#xff0c;主要是在登录界面进行选择。以下是详细的步骤&#xff1a; 步骤 1&#xff1a;退出当前会话 首先&#xff0c;点击屏幕右上角的用户菜单&#xff0c;选择 注销 或 退出&#xff0c;以退出当前…...

【Linux】4.Linux常见指令以及权限理解(2)

文章目录 3. Linux指令3.1 ls指令和rm指令补充3.2 man指令&#xff08;重要&#xff09;3.3cp指令&#xff08;重要&#xff09;输出重定向3.3.1ubuntu20.04如何安装tree 3.4 mv指令&#xff08;重要&#xff09;mv指令更改文件名mv指令更改目录名 如何看待指令指令的重命名3.5…...

ffmpeg aac s16 encode_audio.c

用ffmpeg库时&#xff0c;用代码对pcm内容采用aac编码进行压缩&#xff0c;出现如下错误。 [aac 000002bc5edc6e40] Format aac detected only with low score of 1, misdetection possible! [aac 000002bc5edc8140] Error decoding AAC frame header. [aac 000002bc5edc81…...

口碑好网站建设/推广计划怎么做

超时时间已到。在操作完成之前超时时间已过或服务器未响应”初步分析原因为对MSSQL操作时连接超时&#xff0c;知道这事&#xff0c;以前没留意&#xff0c;大概是在配置文件中设置连接时限&#xff0c;在网上找了下解决方法&#xff0c;大多说在数据库连接字符串里解决 SqlCo…...

河间哪里有做网站的/广州最新疫情通报

1 问题 给定一个二叉树&#xff0c;判断它是否是高度平衡的二叉树。 本题中&#xff0c;一棵高度平衡二叉树定义为&#xff1a;一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1。 示例 1: 给定二叉树 [3,9,20,null,null,15,7] 返回 true 。 示例 2: 给定二叉树…...

wordpress页面是什么/seo基础知识培训视频

* 1.补全代码的声明&#xff1a;alt / * 2.快速修复: ctrl 1 * 3.批量导包&#xff1a;ctrl shift o * 4.使用单行注释&#xff1a;ctrl / * 5.使用多行注释&#xff1a; ctrl shift / * 6.取消多行注释&#xff1a;ctrl shift \ * 7.复制指定行的代码&#xff1a;ctr…...

网站建设百度小程序/赵阳竞价培训

由于公司的业务需要&#xff0c;要实现PhoneGAP文件上传并显示进度条。一开始没有仔细看PhoneGAP API就草草开工&#xff0c;后来通过logcat才发现&#xff0c;上传过程中居然有动态刷新上传的字节数据。顿时泪奔&#xff0c;我手动实现的上传进度监听啊&#xff0c;不过既然写…...

经济与政府网站建设/寻找客户资源的网站

2019独角兽企业重金招聘Python工程师标准>>> 1.指定目录打jar包 (单模块打包) <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.1.0</version><configurat…...

怎么做好网站运营/seo优化教程下载

Oracle database filesystem (DBFS) 简单配置文档本机环境&#xff1a;11.2.0.11. download fuse package on websitedownload 2.7.4 版本看一下需要的rpm包rpm -q kernel-develkernel-devel-2.6.18-308.el52. 安装fusetar -xzvf fuse-2.7.4.tar.gz./configuremakemake install…...