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

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

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

创建springboot项目

目录 1、使用 https://start.spring.io/ 创建项目Project 选 mavenLanguage 选 javaSpring Boot 选 3.4.1Project MetadataDependencies 2、阿里云网址 更好用 https://start.aliyun.com/ 1、使用 https://start.spring.io/ 创建项目 跳转 Project 选 maven Language 选 jav…

UDP_TCP

目录 1. 回顾端口号2. UDP协议2.1 理解报头2.2 UDP的特点2.3 UDP的缓冲区及注意事项 3. TCP协议3.1 报头3.2 流量控制2.3 数据发送模式3.4 捎带应答3.5 URG && 紧急指针3.6 PSH3.7 RES 1. 回顾端口号 在 TCP/IP 协议中&#xff0c;用 “源IP”&#xff0c; “源端口号”…

Netron可视化深度学习的模型框架,大大降低了大模型的学习门槛

深度学习是机器学习的一个子领域&#xff0c;灵感来源于人脑的神经网络。深度学习通过多层神经网络自动提取数据中的高级特征&#xff0c;能够处理复杂和大量的数据&#xff0c;尤其在图像、语音、自然语言处理等任务中表现出色。常见的深度学习模型&#xff1a; 卷积神经网络…

Python生成高级圣诞树-代码案例剖析

文章目录 &#x1f47d;发现宝藏 ❄️方块圣诞树&#x1f42c;效果截图&#x1f338;代码-可直接运行&#x1f334;代码解析 ❄️线条圣诞树&#x1f42c;效果截图&#x1f338;代码-可直接运行&#x1f334;代码解析 ❄️豪华圣诞树&#x1f42c;效果截图&#x1f338;代码-可…

Flux“炼丹炉”——fluxgym安装教程

一、介绍 这个炼丹炉目前可以训练除了flux-dev之外的其它模型&#xff0c;只需更改一个配置文件内容即可。重要的是训练时不需要提前进行图片裁剪、打标等前置工作&#xff0c;只需下图的三个步骤即可开始训练。它就是——fluxgym。 fluxgym&#xff1a;用于训练具有低 VRAM &…

【PLL】非线性瞬态性能

频率捕获、跟踪响应&#xff0c;是大信号非线性行为锁相范围内的相位、频率跟踪&#xff0c;不是非线性行为 所以&#xff1a;跟踪&#xff0c;是线性区域&#xff1b;捕获&#xff0c;是大信号、非线性区域 锁定范围&#xff1a;没有周跳&#xff08;cycle-slipping&#xff0…

OpenAI CEO 奥特曼发长文《反思》

OpenAI CEO 奥特曼发长文《反思》 --- 引言&#xff1a;从 ChatGPT 到 AGI 的探索 ChatGPT 诞生仅一个多月&#xff0c;如今我们已经过渡到可以进行复杂推理的下一代模型。新年让人们陷入反思&#xff0c;我想分享一些个人想法&#xff0c;谈谈它迄今为止的发展&#xff0c;…

“AI智慧语言训练系统:让语言学习变得更简单有趣

大家好&#xff0c;我是你们的老朋友&#xff0c;一个热衷于探讨科技与教育结合的产品经理。今天&#xff0c;我想和大家聊聊一个让语言学习变得不再头疼的话题——AI智慧语言训练系统。这个系统可是我们语言学习者的福音&#xff0c;让我们一起来揭开它的神秘面纱吧&#xff0…

一、二极管(应用篇)

1.5普通二极管应用 1.5.1钳位电路 利用二极管的固定的导通电压&#xff0c;在二极管处并联用电器&#xff0c;达到用电器的工作电压相对稳定。如果电源处有尖峰电压&#xff0c;则可以通过二极管导入到5v的电源内&#xff0c;防止此尖峰电压干扰用电器 &#xff0c;起到对电路的…

Android Studio 安装配置(个人笔记)

Android studio安装的前提是必须保证安装了jdk1.8版本以上 一、查看是否安装jdk cmd打开命令行&#xff0c;输入java -version 最后是一个关键点 输入 javac &#xff0c;看看有没有相关信息 没有就下载jdk Android studio安装的前提是必须保证安装了jdk1.8版本以上 可以到…

unity学习14:unity里的C#脚本的几个基本生命周期方法, 脚本次序order等

目录 1 初始的C# 脚本 1.1 初始的C# 脚本 1.2 创建时2个默认的方法 2 常用的几个生命周期方法 2.1 脚本的生命周期 2.1.1 其中FixedUpdate 方法 的时间间隔&#xff0c;是在这设置的 2.2 c#的基本语法别搞混 2.2.1 基本的语法 2.2.2 内置的方法名&#xff0c;要求更严…

node.js|浏览器插件|Open-Multiple-URLs的部署和使用,实现一键打开多个URL的强大工具

前言&#xff1a; 在整理各类资源的时候&#xff0c;可能会面临资源非常多的情况&#xff0c;这个时候我们就需要一款能够一键打开多个URL的浏览器插件了 说简单点&#xff0c;其实&#xff0c;迅雷就是这样的&#xff0c;但是迅雷是基于内置nginx浏览器实现的&#xff0c;并…

HTML 显示器纯色亮点检测工具

HTML 显示器纯色亮点检测工具 相关资源文件已经打包成html等文件&#xff0c;可双击直接运行程序&#xff0c;且文章末尾已附上相关源码&#xff0c;以供大家学习交流&#xff0c;博主主页还有更多Html相关程序案例&#xff0c;秉着开源精神的想法&#xff0c;望大家喜欢&#…

dbeaver导入导出数据库(sql文件形式)

目录 前言dbeaver导出数据库dbeaver导入数据库 前言 有时候我们需要复制一份数据库&#xff0c;可以使用dbeaver简单操作&#xff01; dbeaver导出数据库 选中数据库右键->工具->转储数据库 dbeaver导入数据库 选中数据库右键->工具->执行脚本 mysql 默…

接口测试-postman(使用postman测试接口笔记)

一、设置全局变量 1. 点击右上角设置按钮-》打开管理环境窗口-》选择”全局“-》设置变量名称&#xff0c;初始值和当前值设置一样的&#xff0c;放host放拼接的url&#xff0c;key放鉴权那一串字符&#xff0c;然后保存-》去使用全局变量&#xff0c;用{{变量名称}}形式 二、…

enzymejest TDD与BDD开发实战

一、前端自动化测试需要测什么 1. 函数的执行逻辑&#xff0c;对于给定的输入&#xff0c;输出是否符合预期。 2. 用户行为的响应逻辑。 - 对于单元测试而言&#xff0c;测试粒度较细&#xff0c;需要测试内部状态的变更与相应函数是否成功被调用。 - 对于集成测试而言&a…

Flutter项目开发模版,开箱即用(Plus版本)

前言 当前案例 Flutter SDK版本&#xff1a;3.22.2 本文&#xff0c;是由这两篇文章 结合产出&#xff0c;所以非常建议大家&#xff0c;先看完这两篇&#xff1a; Flutter项目开发模版&#xff1a; 主要内容&#xff1a;MVVM设计模式及内存泄漏处理&#xff0c;涉及Model、…

Spring Boot - 日志功能深度解析与实践指南

文章目录 概述1. Spring Boot 日志功能概述2. 默认日志框架&#xff1a;LogbackLogback 的核心组件Logback 的配置文件 3. 日志级别及其配置配置日志级别3.1 配置文件3.2 环境变量3.3 命令行参数 4. 日志格式自定义自定义日志格式 5. 日志文件输出6. 日志归档与清理7. 自定义日…

IWOA-GRU和GRU时间序列预测(改进的鲸鱼算法优化门控循环单元)

时序预测 | MATLAB实现IWOA-GRU和GRU时间序列预测(改进的鲸鱼算法优化门控循环单元) 目录 时序预测 | MATLAB实现IWOA-GRU和GRU时间序列预测(改进的鲸鱼算法优化门控循环单元)预测效果基本介绍模型描述程序设计参考资料 预测效果 基本介绍 MATLAB实现IWOA-GRU和GRU时间序列预测…

【SpringBoot】日志处理-异常日志(Logback)

文章目录 异常日志&#xff08;Logback&#xff09;1、将 logback-spring.xml 文件放入项目的 src/main/resources 目录下2、配置 application.yml 文件3、使用 Logback 记录日志 异常日志&#xff08;Logback&#xff09; 使用 Logback 作为日志框架时&#xff0c;可以通过配…