开源鸿蒙 Environment

  • 2022-08-09
  • 浏览 (659)

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

key Parameter Return Value Description
EnvProp key: string,
defaultValue: any
boolean Binds 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.
EnvProps keys: {
key: string,
defaultValue: any
}[]
void Associates this system item array with the AppStorage.
Keys Array<string> number Returns the associated system item array.

Built-in Environment Variables

| key | Type | Description | | ——– | ——– | ——– | | accessibilityEnabled | boolean | Whether to enable accessibility. | | colorMode | ColorMode | Color mode. The options are as follows:
- ColorMode.LIGHT: light mode.
- ColorMode.DARK: dark mode. | | fontScale | number | Font scale. The value range is [0.85, 1.45]. | | fontWeightScale | number | Font weight scale. The value range is [0.6, 1.6]. | | layoutDirection | LayoutDirection | Layout direction. The options are as follows:
- LayoutDirection.LTR: The direction is from left to right.
- LayoutDirection.RTL: The direction is from right to left. | | languageCode | string | Current 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

0  赞