开源鸿蒙 Environment

2022-08-09 浏览 (972)

Environment

Environment is a singleton object created by the framework when the application is started. It provides the AppStorage with a series of environment state attributes required by the application. These attributes describe the device environment where the application runs. Environment and its attributes are immutable, and all attribute values are of the simple type. The following example shows how to obtain the semantic environment from Environment:

Environment.EnvProp("accessibilityEnabled", "default");
var enable = AppStorage.Get("accessibilityEnabled");

accessibilityEnabled is the default system variable identifier provided by Environment. You need to bind the corresponding system attribute to the AppStorage. Then, you can use the methods or decorators in the AppStorage to access the corresponding system attribute data.

Environment APIs

keyParameterReturn ValueDescription
EnvPropkey: string,
defaultValue: any
booleanBinds this system attribute to the AppStorage. You are advised to use this API during application startup. If the attribute already exists in the AppStorage, false is returned. Do not use the variables in the AppStorage. Instead, call this method to bind environment variables.
EnvPropskeys: {
key: string,
defaultValue: any
}[]
voidAssociates this system item array with the AppStorage.
KeysArray<string>numberReturns the associated system item array.

Built-in Environment Variables

keyTypeDescription
accessibilityEnabledbooleanWhether to enable accessibility.
colorModeColorModeColor mode. The options are as follows:
- ColorMode.LIGHT: light mode.
- ColorMode.DARK: dark mode.
fontScalenumberFont scale. The value range is [0.85, 1.45].
fontWeightScalenumberFont weight scale. The value range is [0.6, 1.6].
layoutDirectionLayoutDirectionLayout direction. The options are as follows:
- LayoutDirection.LTR: The direction is from left to right.
- LayoutDirection.RTL: The direction is from right to left.
languageCodestringCurrent system language. The value is in lowercase, for example, zh.

你可能感兴趣的文章

开源鸿蒙 UI Development

开源鸿蒙 ArkUI Overview

开源鸿蒙 File Organization

开源鸿蒙 app.js

开源鸿蒙 “js” Tag

开源鸿蒙 Lifecycle

开源鸿蒙 Multi-Language Capability

开源鸿蒙 Resource Limitations and Access

开源鸿蒙 CSS

开源鸿蒙 HML

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/023ac2468e14437d9ec13b1b46ecf472