# Window The `Window` module provides basic window management capabilities, such as creating and destroying the current window, setting properties for the current window, and managing and scheduling windows. This module provides the following common window-related functions: - [Window](#window): the current window instance, which is the basic unit managed by the window manager. - [WindowStage](#windowstage9): window manager that manages windows. > **NOTE** > > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import ```js import window from '@ohos.window'; ``` ## WindowType7+ Enumerates the window types. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Value| Description | | ----------------- | ------ | ------------------ | | TYPE_APP | 0 | Application subwindow.
**Model restriction**: This API can be used only in the FA model.| | TYPE_SYSTEM_ALERT | 1 | System alert window.| | TYPE_INPUT_METHOD9+ | 2 | Input method window.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_STATUS_BAR9+ | 3 | Status bar.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_PANEL9+ | 4 | Notification panel.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_KEYGUARD9+ | 5 | Lock screen.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_VOLUME_OVERLAY9+ | 6 | Volume bar.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_NAVIGATION_BAR9+ | 7 | Navigation bar.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_FLOAT9+ | 8 | Floating window.
**Model restriction**: This API can be used only in the stage model.
**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW| | TYPE_WALLPAPER9+ | 9 | Wallpaper.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_DESKTOP9+ | 10 | Home screen.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_LAUNCHER_RECENT9+ | 11 | Recent tasks screen.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_LAUNCHER_DOCK9+ | 12 | Dock bar on the home screen.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_VOICE_INTERACTION9+ | 13 | Voice assistant.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_POINTER9+ | 14 | Mouse.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_FLOAT_CAMERA9+ | 15 | Floating camera window.
**Model restriction**: This API can be used only in the stage model.
**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW| | TYPE_DIALOG9+ | 16 | Modal window.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| | TYPE_SCREENSHOT9+ | 17 | Screenshot window.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.| ## AvoidAreaType7+ Enumerates the types of the area where the window cannot be displayed. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Value | Description | |----------------------------------|-----| ----------------- | | TYPE_SYSTEM | 0 | Default area of the system.| | TYPE_CUTOUT | 1 | Notch. | | TYPE_SYSTEM_GESTURE9+ | 2 | Gesture area. | | TYPE_KEYBOARD9+ | 3 | Soft keyboard area. | ## WindowMode7+ Enumerates the window modes. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Value | Description | | ---------- | ---- | ----------------------------- | | UNDEFINED | 1 | The window mode is not defined by the application. | | FULLSCREEN | 2 | The application is displayed in full screen. | | PRIMARY | 3 | The application is displayed in the primary window in split-screen mode. | | SECONDARY | 4 | The application is displayed in the secondary window in split-screen mode. | | FLOATING | 5 | The application is displayed in a floating window.| ## WindowLayoutMode9+ Enumerates the window layout modes. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Value | Description | | ---------- | ---- | ----------------------------- | | WINDOW_LAYOUT_MODE_CASCADE | 0 | Cascade mode. | | WINDOW_LAYOUT_MODE_TILE | 1 | Tile mode. | ## SystemBarProperties Describes the properties of the status bar and navigation bar. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type| Readable| Writable| Description | | -------------------------------------- | -------- | ---- | ---- | ------------------------------------------------------------ | | statusBarColor | string | Yes | Yes | Background color of the status bar. The value is a hexadecimal RGB or aRGB color value and is case insensitive, for example, `#00FF00` or `#FF00FF00`.| | isStatusBarLightIcon7+ | boolean | No | Yes | Whether any icon on the status bar is highlighted. | | statusBarContentColor8+ | string | No | Yes | Color of the text on the status bar. | | navigationBarColor | string | Yes | Yes | Background color of the navigation bar. The value is a hexadecimal RGB or aRGB color value and is case insensitive, for example, `#00FF00` or `#FF00FF00`.| | isNavigationBarLightIcon7+ | boolean | No | No | Whether any icon on the navigation bar is highlighted. | | navigationBarContentColor8+ | string | No | Yes | Color of the text on the navigation bar. | ## Orientation9+ Enumerates the window orientations. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Value | Description | | ------------------------------------- | ---- | ----------------------------- | | UNSPECIFIED | 0 | Unspecified. The orientation is determined by the system.| | PORTRAIT | 1 | Portrait. | | LANDSCAPE | 2 | Landscape. | | PORTRAIT_INVERTED | 3 | Reverse portrait. | | LANDSCAPE_INVERTED | 4 | Reverse landscape.| | AUTO_ROTATION | 5 | Auto rotation.| | AUTO_ROTATION_PORTRAIT | 6 | Auto rotation in the vertical direction.| | AUTO_ROTATION_LANDSCAPE | 7 | Auto rotation in the horizontal direction.| | AUTO_ROTATION_RESTRICTED | 8 | Switched-determined auto rotation.| | AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | Switched-determined auto rotation in the vertical direction.| | AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | Switched-determined auto rotation in the horizontal direction.| | LOCKED | 11 | Locked.| ## BlurStyle9+ Enumerates the window blur styles. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Value | Description | | ------- | ---- | -------------------- | | OFF | 0 | Blur disabled. | | THIN | 1 | Thin blur.| | REGULAR | 2 | Regular blur.| | THICK | 3 | Thick blur.| ## SystemBarRegionTint8+ Describes the callback for a single system bar. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type | Readable| Writable| Description | | --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | | type | [WindowType](#windowtype) | Yes | Yes | Type of the system bar whose properties are changed. Only the status bar and navigation bar are supported.| | isEnable | boolean | Yes | Yes | Whether the system bar is displayed. | | region | [Rect](#rect) | Yes | Yes | Current position and size of the system bar. | | backgroundColor | string | Yes | Yes | Background color of the system bar. The value is a hexadecimal RGB or aRGB color value and is case insensitive, for example, `#00FF00` or `#FF00FF00`.| | contentColor | string | Yes | Yes | Color of the text on the system bar. | ## SystemBarTintState8+ Describes the callback for the current system bar. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type | Readable| Writable| Description | | ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- | | displayId | number | Yes | No | ID of the current physical screen. | | regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | Yes | Yes | All system bar information that has been changed.| ## Rect7+ Describes the rectangular area of the window. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type| Readable| Writable| Description | | ------ | -------- | ---- | ---- | ------------------ | | left | number | Yes | Yes | Left boundary of the rectangle.| | top | number | Yes | Yes | Top boundary of the rectangle.| | width | number | Yes | Yes | Width of the rectangle. | | height | number | Yes | Yes | Height of the rectangle. | ## AvoidArea7+ Describes the area where the window cannot be displayed. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type | Readable| Writable| Description | | ---------- | ------------- | ---- | ---- | ------------------ | | visible9+ | boolean | Yes | Yes | Whether the window can be displayed in the area.| | leftRect | [Rect](#rect) | Yes | Yes | Rectangle on the left of the screen.| | topRect | [Rect](#rect) | Yes | Yes | Rectangle at the top of the screen.| | rightRect | [Rect](#rect) | Yes | Yes | Rectangle on the right of the screen.| | bottomRect | [Rect](#rect) | Yes | Yes | Rectangle at the bottom of the screen.| ## Size7+ Describes the window size. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type| Readable| Writable| Description | | ------ | -------- | ---- | ---- | ---------- | | width | number | Yes | Yes | Window width.| | height | number | Yes | Yes | Window height.| ## WindowProperties Describes the window properties. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type | Readable| Writable| Description | | ------------------------------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | | windowRect7+ | [Rect](#rect) | Yes | Yes | Window size. | | type7+ | [WindowType](#windowtype) | Yes | Yes | Window type. | | isFullScreen | boolean | Yes | Yes | Whether the window is displayed in full screen mode. The default value is `false`. | | isLayoutFullScreen7+ | boolean | Yes | Yes | Whether the window layout is in full-screen mode (whether the window is immersive). The default value is `false`. | | focusable7+ | boolean | Yes | No | Whether the window can gain focus. The default value is `true`. | | touchable7+ | boolean | Yes | No | Whether the window is touchable. The default value is `true`. | | brightness | number | Yes | Yes | Screen brightness. The value ranges from 0 to 1. The value `1` indicates the maximum brightness. | | dimBehindValue(deprecated) | number | Yes | Yes | Dimness of the window that is not on top. The value ranges from 0 to 1. The value `1` indicates the maximum dimness.
**NOTE**
This property is supported since API version 7 and deprecated since API version 9.
| | isKeepScreenOn | boolean | Yes | Yes | Whether the screen is always on. The default value is `false`. | | isPrivacyMode7+ | boolean | Yes | Yes | Whether the window is in privacy mode. The default value is `false`. | | isRoundCorner(deprecated) | boolean | Yes | Yes | Whether the window has rounded corners. The default value is `false`.
**NOTE**
This property is supported since API version 7 and deprecated since API version 9.
| | isTransparent7+ | boolean | Yes | Yes | Whether the window is transparent. The default value is `false`. | ## ColorSpace8+ Describes the color gamut mode. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Default Value | Description | | ---------- | ------ | -------------- | | DEFAULT | 0 | Default color gamut mode.| | WIDE_GAMUT | 1 | Wide color gamut mode. | ## ScaleOptions9+ Describes the scale parameters. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type| Readable| Writable| Description | | ------ | -------- | ---- | ---- | -------------------------------------------------- | | x | number | No | Yes | Scale factor of the x-axis. The default value is `1.0`. | | y | number | No | Yes | Scale factor of the y-axis. The default value is `1.0`. | | pivotX | number | No | Yes | X coordinate of the scale center. The value ranges from 0.0 to 1.0, and the default value is `0.5`.| | pivotY | number | No | Yes | Y coordinate of the scale center. The value ranges from 0.0 to 1.0, and the default value is `0.5`.| ## RotateOptions9+ Describes the rotation parameters. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type| Readable| Writable| Description | | ------ | -------- | ---- | ---- | -------------------------------------------------- | | x | number | No | Yes | Rotation angle around the x-axis. The default value is `0.0`. | | y | number | No | Yes | Rotation angle around the y-axis. The default value is `0.0`. | | z | number | No | Yes | Rotation angle around the z-xis. The default value is `0.0`. | | pivotX | number | No | Yes | X coordinate of the rotation center. The value ranges from 0.0 to 1.0, and the default value is `0.5`.| | pivotY | number | No | Yes | Y coordinate of the rotation center. The value ranges from 0.0 to 1.0, and the default value is `0.5`.| ## TranslateOptions9+ Describes the translation parameters. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name| Type| Readable| Writable| Description | | ---- | -------- | ---- | ---- | ---------------------------- | | x | number | No | Yes | Distance to translate along the x-axis. The default value is `0.0`.| | y | number | No | Yes | Distance to translate along the y-axis. The default value is `0.0`.| | z | number | No | Yes | Distance to translate along the z-axis. The default value is `0.0`.| ## window.create7+ create(id: string, type: WindowType, callback: AsyncCallback<Window>): void Creates a subwindow. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the FA model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------ | | id | string | Yes | Window ID. | | type | [WindowType](#windowtype) | Yes | Window type. | | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created.| **Example** ```js var windowClass = null; window.create("first", window.WindowType.TYPE_APP,(err,data) => { if(err.code){ console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); }); ``` ## window.create7+ create(id: string, type: WindowType): Promise<Window> Creates a subwindow. This API uses a promise to return the result. **Model restriction**: This API can be used only in the FA model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------------------------- | ---- | ---------- | | id | string | Yes | Window ID. | | type | [WindowType](#windowtype) | Yes | Window type.| **Return value** | Type | Description | | -------------------------------- | --------------------------------------- | | Promise<[Window](#window)> | Promise used to return the subwindow created.| **Example** ```js var windowClass = null; let promise = window.create("first", window.WindowType.TYPE_APP); promise.then((data)=> { windowClass = data; console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); }); ``` ## window.create8+ create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback<Window>): void Creates a subwindow (in API version 8) or a system window (from API version 9). This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | | ctx | Context | Yes | Current application context.
For the definition of `Context` of API version 8, see [Context](js-apis-Context.md).
For the definition of `Context` of API version 9, see [ServiceExtensionContext](js-apis-service-extension-context.md).| | id | string | Yes | Window ID. | | type | [WindowType](#windowtype) | Yes | Window type. | | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created. | **Example** ```js var windowClass = null; window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { if (err.code) { console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); windowClass.resetSize(500, 1000); }); ``` ## window.create8+ create(ctx: Context, id: string, type: WindowType): Promise<Window> Creates a subwindow (in API version 8) or a system window (from API version 9). This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------------------------- | ---- | ------------------------------------------------------------ | | ctx | Context | Yes | Current application context.
For the definition of `Context` of API version 8, see [Context](js-apis-Context.md).
For the definition of `Context` of API version 9, see [ServiceExtensionContext](js-apis-service-extension-context.md).| | id | string | Yes | Window ID. | | type | [WindowType](#windowtype) | Yes | Window type. | **Return value** | Type | Description | | -------------------------------- | --------------------------------------- | | Promise<[Window](#window)> | Promise used to return the subwindow created.| **Example** ```js var windowClass = null; let promise = window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT); promise.then((data)=> { windowClass = data; console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); }); ``` ## window.find7+ find(id: string, callback: AsyncCallback<Window>): void Finds a window based on the ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------ | | id | string | Yes | Window ID. | | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the window found.| **Example** ```js var windowClass = null; window.find("alertWindow", (err, data) => { if (err.code) { console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); }); ``` ## window.find7+ find(id: string): Promise<Window> Finds a window based on the ID. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------- | | id | string | Yes | Window ID.| **Return value** | Type | Description | | -------------------------------- | ------------------------------------- | | Promise<[Window](#window)> | Promise used to return the window found.| **Example** ```js var windowClass = null; let promise = window.find("alertWindow"); promise.then((data)=> { windowClass = data; console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); }); ``` ## window.getTopWindow getTopWindow(callback: AsyncCallback<Window>): void Obtains the top window of the current application. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the FA model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | -------------------------------------------- | | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained.| **Example** ```js var windowClass = null; window.getTopWindow((err, data) => { if (err.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); }); ``` ## window.getTopWindow getTopWindow(): Promise<Window> Obtains the top window of the current application. This API uses a promise to return the result. **Model restriction**: This API can be used only in the FA model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | -------------------------------- | ----------------------------------------------- | | Promise<[Window](#window)> | Promise used to return the top window obtained.| **Example** ```js var windowClass = null; let promise = window.getTopWindow(); promise.then((data)=> { windowClass = data; console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); }) ``` ## window.getTopWindow8+ getTopWindow(ctx: Context, callback: AsyncCallback<Window>): void Obtains the top window of the current application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | | ctx | Context | Yes | Current application context.
For the definition of `Context` of API version 8, see [Context](js-apis-Context.md).
For the definition of `Context` of API version 9, see [AbilityContext](js-apis-ability-context.md).| | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained. | **Example** ```js var windowClass = null; window.getTopWindow(this.context, (err, data) => { if (err.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); }); ``` ## window.getTopWindow8+ getTopWindow(ctx: Context): Promise<Window> Obtains the top window of the current application. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ------------------------------------------------------------ | | ctx | Context | Yes | Current application context.
For the definition of `Context` of API version 8, see [Context](js-apis-Context.md).
For the definition of `Context` of API version 9, see [AbilityContext](js-apis-ability-context.md).| **Return value** | Type | Description | | -------------------------------- | ----------------------------------------------- | | Promise<[Window](#window)> | Promise used to return the top window obtained.| **Example** ```js var windowClass = null; let promise = window.getTopWindow(this.context); promise.then((data)=> { windowClass = data; console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); }) ``` ## window.minimizeAll9+ minimizeAll(id: number, callback: AsyncCallback<void>): void Minimizes all windows on a display. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------- | | id | number | Yes | ID of the [display](js-apis-display.md#display).| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js import display from '@ohos.display' import window from '@ohos.window' var displayClass = null; display.getDefaultDisplay((err, data) => { if(err.code) { return; } displayClass = data; window.minimizeAll(displayClass.id, (err, data) => { if(err.code) { console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in minimizing all windows.'); }); }); ``` ## window.minimizeAll9+ minimizeAll(id: number): Promise<void> Minimizes all windows on a display. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------- | | id | number | Yes | ID of the [display](js-apis-display.md#display).| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js import display from '@ohos.display' import window from '@ohos.window' var displayClass = null; display.getDefaultDisplay((err, data) => { if(err.code) { return; } displayClass = data; let promise = window.minimizeAll(displayClass.id); promise.then((data)=> { console.info('Succeeded in minimizing all windows.'); }).catch((err)=>{ console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); }) }); ``` ## window.toggleShownStateForAllAppWindows9+ toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void Hides or restores the application's windows during quick multi-window switching. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js window.toggleShownStateForAllAppWindows((err, data) => { if (err.code) { console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in toggling shown state for all app windows.'); }) ``` ## window.toggleShownStateForAllAppWindows9+ toggleShownStateForAllAppWindows(): Promise<void> Hides or restores the application's windows during quick multi-window switching. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = window.toggleShownStateForAllAppWindows(); promise.then((data)=> { console.info('Succeeded in toggling shown state for all app windows. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); }) ``` ## window.setWindowLayoutMode9+ setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void Sets the window layout mode. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------- | | mode | [WindowLayoutMode](#windowlayoutmode9) | Yes | Window layout mode to set.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (data) => { console.info('Succeeded in setting window layout mode. Data: ' + JSON.stringify(data)); }); ``` ## window.setWindowLayoutMode9+ setWindowLayoutMode(mode: WindowLayoutMode): Promise<void> Sets the window layout mode. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------- | | mode | [WindowLayoutMode](#windowlayoutmode9) | Yes | Window layout mode to set.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE); promise.then((data)=> { console.info('Succeeded in setting window layout mode. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); }) ``` ## on('systemBarTintChange')8+ on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void Enables listening for properties changes of the status bar and navigation bar. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `systemBarTintChange`, indicating the property change event of the status bar and navigation bar.| | callback | Callback<[SystemBarTintState](#systembartintstate)> | Yes | Callback used to return the properties of the status bar and navigation bar. | **Example** ```js window.on('systemBarTintChange', (data) => { console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data)); }); ``` ## off('systemBarTintChange')8+ off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void Disables listening for properties changes of the status bar and navigation bar. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `systemBarTintChange`, indicating the property change event of the status bar and navigation bar.| | callback | Callback<[SystemBarTintState](#systembartintstate)> | No | Callback used to return the properties of the status bar and navigation bar. | **Example** ```js window.off('systemBarTintChange'); ``` ## Window Represents the current window instance, which is the basic unit managed by the window manager. In the following API examples, you must use [getTopWindow()](#windowgettopwindow), [create()](#windowcreate7), or [find()](#windowfind7) to obtain a `Window` instance and then call a method in this instance. ### hide7+ hide (callback: AsyncCallback<void>): void Hides this window. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js windowClass.hide((err, data) => { if (err.code) { console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in hiding the window. data: ' + JSON.stringify(data)); }) ``` ### hide7+ hide(): Promise<void> Hides this window. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.hide(); promise.then((data)=> { console.info('Succeeded in hiding the window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); }) ``` ### hideWithAnimation9+ hideWithAnimation(callback: AsyncCallback<void>): void Hides this window and plays an animation during the process. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js windowClass.hideWithAnimation((err, data) => { if (err.code) { console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in hiding the window with animation. data: ' + JSON.stringify(data)); }) ``` ### hideWithAnimation9+ hideWithAnimation(): Promise<void> Hides this window and plays an animation during the process. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.hideWithAnimation(); promise.then((data)=> { console.info('Succeeded in hiding the window with animation. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); }) ``` ### show7+ show(callback: AsyncCallback<void>): void Shows this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js windowClass.show((err, data) => { if (err.code) { console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data)); }) ``` ### show7+ show(): Promise<void> Shows this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.show(); promise.then((data)=> { console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); }) ``` ### showWithAnimation9+ showWithAnimation(callback: AsyncCallback<void>): void Shows this window and plays an animation during the process. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js windowClass.showWithAnimation((err, data) => { if (err.code) { console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); }) ``` ### showWithAnimation9+ showWithAnimation(): Promise<void> Shows this window and plays an animation during the process. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.showWithAnimation(); promise.then((data)=> { console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); }) ``` ### destroy7+ destroy(callback: AsyncCallback<void>): void Destroys this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js windowClass.destroy((err, data) => { if (err.code) { console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data)); }) ``` ### destroy7+ destroy(): Promise<void> Destroys this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.destroy(); promise.then((data)=> { console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); }) ``` ### moveTo7+ moveTo(x: number, y: number, callback: AsyncCallback<void>): void Moves this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ------------------------------------------------- | | x | number | Yes | Distance that the window moves along the x-axis, in px. A positive value indicates that the window moves to the right.| | y | number | Yes | Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js windowClass.moveTo(300, 300, (err, data)=>{ if (err.code) { console.error('Failed to move the window. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in moving the window. Data: ' + JSON.stringify(data)); }); ``` ### moveTo7+ moveTo(x: number, y: number): Promise<void> Moves this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------- | | x | number | Yes | Distance that the window moves along the x-axis, in px. A positive value indicates that the window moves to the right.| | y | number | Yes | Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.moveTo(300, 300); promise.then((data)=> { console.info('Succeeded in moving the window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); }) ``` ### resetSize7+ resetSize(width: number, height: number, callback: AsyncCallback<void>): void Changes the size of this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------------- | | width | number | Yes | New width of the window, in px.| | height | number | Yes | New height of the window, in px.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js windowClass.resetSize(500, 1000, (err, data) => { if (err.code) { console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in changing the window size. Data: ' + JSON.stringify(data)); }); ``` ### resetSize7+ resetSize(width: number, height: number): Promise<void> Changes the size of this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------------------------- | | width | number | Yes | New width of the window, in px.| | height | number | Yes | New height of the window, in px.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.resetSize(500, 1000); promise.then((data)=> { console.info('Succeeded in changing the window size. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); }); ``` ### setWindowType(deprecated) setWindowType(type: WindowType, callback: AsyncCallback<void>): void Sets the type of this window. This API uses an asynchronous callback to return the result. **System API**: This is a system API. > **NOTE**
This API is supported since API version 7 and deprecated since API version 9. > > **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | type | [WindowType](#windowtype) | Yes | Window type.| | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js var type = window.WindowType.TYPE_APP; windowClass.setWindowType(type, (err, data) => { if (err.code) { console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data)); }); ``` ### setWindowType(deprecated) setWindowType(type: WindowType): Promise<void> Sets the type of this window. This API uses a promise to return the result. **System API**: This is a system API. > **NOTE**
This API is supported since API version 7 and deprecated since API version 9. > > **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------------------------- | ---- | ---------- | | type | [WindowType](#windowtype) | Yes | Window type.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var type = window.WindowType.TYPE_APP; let promise = windowClass.setWindowType(type); promise.then((data)=> { console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); }); ``` ### getProperties getProperties(callback: AsyncCallback<WindowProperties>): void Obtains the properties of this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------------------- | ---- | ---------------------------- | | callback | AsyncCallback<[WindowProperties](#windowproperties)> | Yes | Callback used to return the window properties.| **Example** ```js windowClass.getProperties((err, data) => { if (err.code) { console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); }); ``` ### getProperties getProperties(): Promise<WindowProperties> Obtains the properties of this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ---------------------------------------------------- | ------------------------------- | | Promise<[WindowProperties](#windowproperties)> | Promise used to return the window properties.| **Example** ```js let promise = windowClass.getProperties(); promise.then((data)=> { console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); }); ``` ### getAvoidArea7+ getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void Obtains the area where this window cannot be displayed, for example, the system bar area and notch. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | | type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area. `TYPE_SYSTEM` indicates the default area of the system. `TYPE_CUTOUT` indicates the notch. `TYPE_SYSTEM_GESTURE` indicates the gesture area. `TYPE_KEYBOARD` indicates the soft keyboard area.| | callback | AsyncCallback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | **Example** ```js var type = window.AvoidAreaType.TYPE_SYSTEM; windowClass.getAvoidArea(type, (err, data) => { if (err.code) { console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); }); ``` ### getAvoidArea7+ getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> Obtains the area where this window cannot be displayed, for example, the system bar area and notch. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ |----------------------------------| ---- | ------------------------------------------------------------ | | type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area. `TYPE_SYSTEM` indicates the default area of the system. `TYPE_CUTOUT` indicates the notch. `TYPE_SYSTEM_GESTURE` indicates the gesture area. `TYPE_KEYBOARD` indicates the soft keyboard area.| **Return value** | Type | Description | |-----------------------------------------| ----------------------------------- | | Promise<[AvoidArea](#avoidarea7)> | Promise used to return the area.| **Example** ```js let promise = windowClass.getAvoidArea(); promise.then((data)=> { console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); }); ``` ### setFullScreen setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void Sets whether to enable the full-screen mode for this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------ | ------------------------- | ---- | ---------------------------------------------- | | isFullScreen | boolean | Yes | Whether to enable the full-screen mode, in which the status bar and navigation bar are hidden.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isFullScreen = true; windowClass.setFullScreen(isFullScreen, (err, data) => { if (err.code) { console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data)); }); ``` ### setFullScreen setFullScreen(isFullScreen: boolean): Promise<void> Sets whether to enable the full-screen mode for this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------ | ------- | ---- | ---------------------------------------------- | | isFullScreen | boolean | Yes | Whether to enable the full-screen mode, in which the status bar and navigation bar are hidden.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isFullScreen = true; let promise = windowClass.setFullScreen(isFullScreen); promise.then((data)=> { console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); }); ``` ### setLayoutFullScreen7+ setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void Sets whether to enable the full-screen mode for the window layout. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | | isLayoutFullScreen | boolean | Yes | Whether to enable the full-screen mode for the window layout, in which the status bar and navigation bar are displayed.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isLayoutFullScreen= true; windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => { if (err.code) { console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data)); }); ``` ### setLayoutFullScreen7+ setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> Sets whether to enable the full-screen mode for the window layout. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------------ | ------- | ---- | ------------------------------------------------------------ | | isLayoutFullScreen | boolean | Yes | Whether to enable the full-screen mode for the window layout, in which the status bar and navigation bar are displayed.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isLayoutFullScreen = true; let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); promise.then((data)=> { console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); }); ``` ### setSystemBarEnable7+ setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void Sets whether to display the status bar and navigation bar in this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ------------------------------------------------------------ | | names | Array | Yes | Whether to display the status bar and navigation bar.
For example, to display the status bar and navigation bar, set this parameter to `["status", "navigation"]`. By default, they are not displayed.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js // In this example, the status bar and navigation bar are not displayed. var names = []; windowClass.setSystemBarEnable(names, (err, data) => { if (err.code) { console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the system bar to be invisible. Data: ' + JSON.stringify(data)); }); ``` ### setSystemBarEnable7+ setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> Sets whether to display the status bar and navigation bar in this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ----- | ---- | ------------------------------------------------------------ | | names | Array | Yes | Whether to display the status bar and navigation bar.
For example, to display the status bar and navigation bar, set this parameter to `["status", "navigation"]`. By default, they are not displayed.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js // In this example, the status bar and navigation bar are not displayed. var names = []; let promise = windowClass.setSystemBarEnable(names); promise.then((data)=> { console.info('Succeeded in setting the system bar to be invisible. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); }); ``` ### setSystemBarProperties setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void Sets the properties of the status bar and navigation bar in this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------------- | ------------------------------------------- | ---- | ---------------------- | | SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var SystemBarProperties={ statusBarColor: '#ff00ff', navigationBarColor: '#00ff00', // The following properties are supported since API version 7. isStatusBarLightIcon: true, isNavigationBarLightIcon:false, // The following properties are supported since API version 8. statusBarContentColor:'#ffffff', navigationBarContentColor:'#00ffff' }; windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => { if (err.code) { console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data)); }); ``` ### setSystemBarProperties setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> Sets the properties of the status bar and navigation bar in this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------------- | ------------------------------------------- | ---- | ---------------------- | | SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var SystemBarProperties={ statusBarColor: '#ff00ff', navigationBarColor: '#00ff00', // The following properties are supported since API version 7. isStatusBarLightIcon: true, isNavigationBarLightIcon:false, // The following properties are supported since API version 8. statusBarContentColor:'#ffffff', navigationBarContentColor:'#00ffff' }; let promise = windowClass.setSystemBarProperties(SystemBarProperties); promise.then((data)=> { console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); }); ``` ### setPreferredOrientation9+ setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void Sets the preferred orientation for this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------------- | ------------------------------------------- | ---- | ---------------------- | | Orientation | [Orientation](#orientation9) | Yes | Orientation to set. | | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var orientation = window.Orientation.AUTO_ROTATION; windowClass.setPreferredOrientation(orientation, (err, data) => { if (err.code) { console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting window orientation. Data: ' + JSON.stringify(data)); }); ``` ### setPreferredOrientation9+ setPreferredOrientation(orientation: Orientation): Promise<void> Sets the preferred orientation for this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------------- | ------------------------------------------- | ---- | ---------------------- | | Orientation | [Orientation](#orientation9) | Yes | Orientation to set. | **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var orientation = window.Orientation.AUTO_ROTATION; let promise = windowClass.setPreferredOrientation(orientation); promise.then((data)=> { console.info('Succeeded in setting the window orientation. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err)); }); ``` ### loadContent7+ loadContent(path: string, callback: AsyncCallback<void>): void Loads content from a page to this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------- | | path | string | Yes | Path of the page from which the content will be loaded.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js windowClass.loadContent("pages/page2/page2", (err, data) => { if (err.code) { console.error('Failed to load the content. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }); ``` ### loadContent7+ loadContent(path: string): Promise<void> Loads content from a page to this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------------------- | | path | string | Yes | Path of the page from which the content will be loaded.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.loadContent("pages/page2/page2"); promise.then((data)=> { console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); }); ``` ### loadContent9+ loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void Loads content from a page associated with a local storage to this window. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Path of the page from which the content will be loaded. | | storage | [LocalStorage](../../ui/ui-ts-local-storage.md) | Yes | A storage unit, which provides storage for variable state properties and non-variable state properties of an application.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```ts class myAbility extends Ability { storage : LocalStorage onWindowStageCreate(windowStage) { this.storage = new LocalStorage(); this.storage.setOrCreate("storageSimpleProp",121); console.log('onWindowStageCreate'); windowStage.loadContent("pages/page2",this.storage,(err, data) => { if (err.code) { console.error('Failed to load the content. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }); } } ``` ### loadContent9+ loadContent(path: string, storage: LocalStorage): Promise<void> Loads content from a page associated with a local storage to this window. This API uses a promise to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Path of the page from which the content will be loaded. | | storage | [LocalStorage](../../ui/ui-ts-local-storage.md) | Yes | A storage unit, which provides storage for variable state properties and non-variable state properties of an application.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts class myAbility extends Ability { storage : LocalStorage onWindowStageCreate(windowStage) { this.storage = new LocalStorage(); this.storage.setOrCreate("storageSimpleProp",121); console.log('onWindowStageCreate'); var windowClass = null; let promise = windowStage.loadContent("pages/page2",this.storage); promise.then((data)=> { windowClass = data; console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to load the content. Cause:' + JSON.stringify(err)); }) } } ``` ### isShowing7+ isShowing(callback: AsyncCallback<boolean>): void Checks whether this window is displayed. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------------ | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value `true` means that this window is displayed, and `false` means the opposite.| **Example** ```js windowClass.isShowing((err, data) => { if (err.code) { console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); }); ``` ### isShowing7+ isShowing(): Promise<boolean> Checks whether this window is displayed. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ---------------------- | ------------------------------------------------------------ | | Promise<boolean> | Promise used to return the result. The value `true` means that this window is displayed, and `false` means the opposite.| **Example** ```js let promise = windowClass.isShowing(); promise.then((data)=> { console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err)); }); ``` ### on('windowSizeChange')7+ on(type: 'windowSizeChange', callback: Callback<Size>): void Enables listening for window size changes. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------ | ---- | -------------------------------------------------------- | | type | string | Yes | Event type. The value is fixed at `windowSizeChange`, indicating the window size change event.| | callback | Callback<[Size](#size7)> | Yes | Callback used to return the window size. | **Example** ```js windowClass.on('windowSizeChange', (data) => { console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); }); ``` ### off('windowSizeChange')7+ off(type: 'windowSizeChange', callback?: Callback<Size >): void Disables listening for window size changes. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ----------------------------- | ---- | -------------------------------------------------------- | | type | string | Yes | Event type. The value is fixed at `windowSizeChange`, indicating the window size change event.| | callback | Callback<[Size](#size)> | No | Callback used to return the window size. | **Example** ```js windowClass.off('windowSizeChange'); ``` ### on('systemAvoidAreaChange')(deprecated) on(type: 'systemAvoidAreaChange', callback: Callback<[AvoidArea](#avoidarea7)>): void Enables listening for changes to the area where the window cannot be displayed. > **NOTE**
This API is supported since API version 7 and deprecated since API version 9. Use [on('avoidAreaChange')](#onavoidareachange9) instead. > > **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |------------------------------------------| ---- | ------------------------------------------------------- | | type | string | Yes | Event type. The value is fixed at `systemAvoidAreaChange`, indicating the event of changes to the area where the window cannot be displayed.| | callback | Callback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | **Example** ```js windowClass.on('systemAvoidAreaChange', (data) => { console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); }); ``` ### off('systemAvoidAreaChange')(deprecated) off(type: 'systemAvoidAreaChange', callback?: Callback<[AvoidArea](#avoidarea7)>): void Disables listening for changes to the area where the window cannot be displayed. > **NOTE**
This API is supported since API version 7 and deprecated since API version 9. Use [off('avoidAreaChange')](#offavoidareachange9) instead. > > **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |------------------------------------------| ---- | ------------------------------------------------------- | | type | string | Yes | Event type. The value is fixed at `systemAvoidAreaChange`, indicating the event of changes to the area where the window cannot be displayed.| | callback | Callback<[AvoidArea](#avoidarea7)> | No | Callback used to return the area. | **Example** ```js windowClass.off('systemAvoidAreaChange'); ``` ### on('avoidAreaChange')9+ on(type: 'avoidAreaChange', callback: Callback<{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}>): void Enables listening for changes to the area where the window cannot be displayed. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |------------------------------------------------------------------| ---- |--------------------------------------| | type | string | Yes | Event type. The value is fixed at `avoidAreaChange`, indicating the event of changes to the area where the window cannot be displayed.| | callback | Callback<{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}> | Yes | Callback used to return the area and area type.| **Example** ```js windowClass.on('avoidAreaChange', (data) => { console.info('Succeeded in enabling the listener for system avoid area changes. type:' + JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); }); ``` ### off('avoidAreaChange')9+ off(type: 'avoidAreaChange', callback: Callback<{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}>): void Disables listening for changes to the area where the window cannot be displayed. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory | Description | | -------- |-----------------------------------------------------------------------------|-----|------------------------------------| | type | string | Yes | Event type. The value is fixed at `avoidAreaChange`, indicating the event of changes to the area where the window cannot be displayed.| | callback | Callback<{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}> | No | Callback used to return the area and area type.| **Example** ```js windowClass.off('avoidAreaChange'); ``` ### on('keyboardHeightChange')7+ on(type: 'keyboardHeightChange', callback: Callback<number>): void Enables listening for keyboard height changes. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `keyboardHeightChange`, indicating the keyboard height change event.| | callback | Callback { console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); }); ``` ### off('keyboardHeightChange')7+ off(type: 'keyboardHeightChange', callback?: Callback<number>): void Disables listening for keyboard height changes. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `keyboardHeightChange`, indicating the keyboard height change event.| | callback | Callback<number> | No | Callback used to return the current keyboard height. | **Example** ```js windowClass.off('keyboardHeightChange'); ``` ### on('touchOutside')9+ on(type: 'touchOutside', callback: Callback<void>): void Enables listening for click events outside this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `touchOutside`, indicating the click event outside this window.| | callback | Callback { console.info('touch outside'); }); ``` ### off('touchOutside')9+ off(type: 'touchOutside', callback?: Callback<void>): void Disables listening for click events outside this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `touchOutside`, indicating the click event outside this window.| | callback | Callback<number> | No | Callback used to Callback used to return the click event outside this window. | **Example** ```js windowClass.off('touchOutside'); ``` ### on('screenshot')9+ on(type: 'screenshot', callback: Callback<void>): void Subscribes to screenshot events. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| | callback | Callback<void> | Yes | Callback invoked when a screenshot event occurs. | **Example** ```js windowClass.on('screenshot', () => { console.info('screenshot happened'); }); ``` ### off('screenshot')9+ off(type: 'screenshot', callback?: Callback<void>): void Unsubscribes from screenshot events. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| | callback | Callback<void> | No | Callback invoked when a screenshot event occurs.| **Example** ```js var callback = ()=>{ console.info('screenshot happened'); } windowClass.on('screenshot', callback) windowClass.off('screenshot', callback) // If multiple callbacks are enabled in on(), they will all be disabled. windowClass.off('screenshot'); ``` ### on('dialogTargetTouch')9+ on(type: 'dialogTargetTouch', callback: Callback<void>): void Subscribes to click events of the target window in the modal window mode. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click event of the target window in the modal window mode.| | callback | Callback<void>| Yes | Callback invoked when the click event occurs in the target window of the modal window mode.| **Example** ```js windowClass.on('dialogTargetTouch', () => { console.info('touch dialog target'); }); ``` ### off('dialogTargetTouch')9+ off(type: 'dialogTargetTouch', callback?: Callback<void>): void Unsubscribes from click events of the target window in the modal window mode. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------- | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click event of the target window in the modal window mode.| | callback | Callback<void> | No | Callback invoked when the click event occurs in the target window of the modal window mode.| **Example** ```js windowClass.off('dialogTargetTouch'); ``` ### bindDialogTarget9+ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void Binds the modal window to the target window, and adds a callback to listen for modal window destruction events. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------------------------- | ---- | -------------------- | | token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | Yes | Token of the target window.| | deathCallback | Callback<void> | Yes | Callback used to listen for modal window destruction events.| | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js class MyDeathRecipient { onRemoteDied() { console.log("server died"); } } class TestRemoteObject extends rpc.RemoteObject { constructor(descriptor) { super(descriptor); } addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } isObjectDead(): boolean { return false; } } let token = new TestRemoteObject("testObject"); windowClass.bindDialogTarget(token, () => { console.info('Dialog Window Need Destroy.'); }, (err, data) => { if (err.code) { console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in binding dialog target. Data:' + JSON.stringify(data)); }); ``` ### bindDialogTarget9+ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void> Binds the modal window to the target window, and adds a callback to listen for modal window destruction events. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------------------------- | ---- | -------------------- | | token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | Yes | Token of the target window.| | deathCallback | Callback<void> | Yes | Callback used to listen for modal window destruction events.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js class MyDeathRecipient { onRemoteDied() { console.log("server died"); } } class TestRemoteObject extends rpc.RemoteObject { constructor(descriptor) { super(descriptor); } addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } isObjectDead(): boolean { return false; } } let token = new TestRemoteObject("testObject"); let promise = windowClass.bindDialogTarget(token, () => { console.info('Dialog Window Need Destroy.'); }); promise.then((data)=> { console.info('Succeeded in binding dialog target. Data:' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); }); ``` ### isSupportWideGamut8+ isSupportWideGamut(callback: AsyncCallback<boolean>): void Checks whether this window supports the wide color gamut mode. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------------ | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value `true` means that the wide color gamut mode is supported, and `false` means the opposite.| **Example** ```js windowClass.isSupportWideGamut((err, data) => { if (err.code) { console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); }) ``` ### isSupportWideGamut8+ isSupportWideGamut(): Promise<boolean> Checks whether this window supports the wide color gamut mode. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ---------------------- | ------------------------------------------------------------ | | Promise<boolean> | Promise used to return the result. The value `true` means that the wide color gamut mode is supported, and `false` means the opposite.| **Example** ```js let promise = windowClass.isSupportWideGamut(); promise.then((data)=> { console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); }); ``` ### setColorSpace8+ setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void Sets this window to the wide or default color gamut mode. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | ------------ | | colorSpace | [ColorSpace](#colorspace) | Yes | Color gamut mode.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err, data) => { if (err.code) { console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data)); }) ``` ### setColorSpace8+ setColorSpace(colorSpace:ColorSpace): Promise<void> Sets this window to the wide or default color gamut mode. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | -------------- | | colorSpace | [ColorSpace](#colorspace) | Yes | Color gamut mode.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); promise.then((data)=> { console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); }); ``` ### getColorSpace8+ getColorSpace(callback: AsyncCallback<ColorSpace>): void Obtains the color gamut mode of this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | | callback | AsyncCallback<[ColorSpace](#colorspace)> | Yes | Callback used to return the result. When the color gamut mode is obtained successfully, `err` is `undefined`, and `data` is the current color gamut mode.| **Example** ```js windowClass.getColorSpace((err, data) => { if (err.code) { console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); }) ``` ### getColorSpace8+ getColorSpace(): Promise<ColorSpace> Obtains the color gamut mode of this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ---------------------------------------- | ------------------------------- | | Promise<[ColorSpace](#colorspace)> | Promise used to return the current color gamut mode.| **Example** ```js let promise = windowClass.getColorSpace(); promise.then((data)=> { console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err)); }); ``` ### setBackgroundColor setBackgroundColor(color: string, callback: AsyncCallback<void>): void Sets the background color for this window. This API uses an asynchronous callback to return the result. In the stage model, this API must be used after [loadContent](#loadcontent9). **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ------------------------------------------------------------ | | color | string | Yes | Background color to set. The value is a hexadecimal color and is case insensitive, for example, `#00FF00` or `#FF00FF00`.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var color = '#00ff33'; windowClass.setBackgroundColor(color, (err, data) => { if (err.code) { console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data)); }); ``` ### setBackgroundColor setBackgroundColor(color: string): Promise<void> Sets the background color for this window. This API uses a promise to return the result. In the stage model, this API must be used after [loadContent](#loadcontent9). **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | color | string | Yes | Background color to set. The value is a hexadecimal color and is case insensitive, for example, `#00FF00` or `#FF00FF00`.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var color = '#00ff33'; let promise = windowClass.setBackgroundColor(color); promise.then((data)=> { console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); }); ``` ### setWakeUpScreen()9+ setWakeUpScreen(wakeUp: boolean): void; Wakes up the screen. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------------- | ------- | ---- | ---------------------------- | | wakeUp | boolean | Yes | Whether to wake up the screen.| **Example** ```js var wakeUp = true; windowClass.setWakeUpScreen(wakeUp); ``` ### setBrightness setBrightness(brightness: number, callback: AsyncCallback<void>): void Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | ------------------------------------ | | brightness | number | Yes | Brightness to set, which ranges from 0 to 1. The value `1` indicates the brightest.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var brightness = 1; windowClass.setBrightness(brightness, (err, data) => { if (err.code) { console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data)); }); ``` ### setBrightness setBrightness(brightness: number): Promise<void> Sets the screen brightness for this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------ | ---- | ------------------------------------ | | brightness | number | Yes | Brightness to set, which ranges from 0 to 1. The value `1` indicates the brightest.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var brightness = 1; let promise = windowClass.setBrightness(brightness); promise.then((data)=> { console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); }); ``` ### setDimBehind(deprecated) setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void Sets the dimness of the window that is not on top. This API uses an asynchronous callback to return the result. > **NOTE** > > This API cannot be used. > > This API is supported since API version 7 and deprecated since API version 9. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------------- | ------------------------- | ---- | -------------------------------------------------- | | dimBehindValue | number | Yes | Dimness of the window to set. The value ranges from 0 to 1. The value `1` indicates the dimmest.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js windowClass.setDimBehind(0.5, (err, data) => { if (err.code) { console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the dimness. Data:' + JSON.stringify(data)); }); ``` ### setDimBehind(deprecated) setDimBehind(dimBehindValue: number): Promise<void> Sets the dimness of the window that is not on top. This API uses a promise to return the result. > **NOTE** > > This API cannot be used. > > This API is supported since API version 7 and deprecated since API version 9. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------------- | ------ | ---- | -------------------------------------------------- | | dimBehindValue | number | Yes | Dimness of the window to set. The value ranges from 0 to 1. The value `1` indicates the dimmest.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.setDimBehind(0.5); promise.then((data)=> { console.info('Succeeded in setting the dimness. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); }); ``` ### setFocusable7+ setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void Sets whether this window can gain focus. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------------------------- | ---- | ---------------------------- | | isFocusable | boolean | Yes | Whether the window can gain focus.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isFocusable= true; windowClass.setFocusable(isFocusable, (err, data) => { if (err.code) { console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data)); }); ``` ### setFocusable7+ setFocusable(isFocusable: boolean): Promise<void> Sets whether this window can gain focus. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------- | ---- | ---------------------------- | | isFocusable | boolean | Yes | Whether the window can gain focus.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isFocusable= true; let promise = windowClass.setFocusable(isFocusable); promise.then((data)=> { console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); }); ``` ### setKeepScreenOn setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------------- | ------------------------- | ---- | ------------------------ | | isKeepScreenOn | boolean | Yes | Whether to keep the screen always on.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isKeepScreenOn = true; windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => { if (err.code) { console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data)); }); ``` ### setKeepScreenOn setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> Sets whether to keep the screen always on. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------------- | ------- | ---- | ------------------------ | | isKeepScreenOn | boolean | Yes | Whether to keep the screen always on.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isKeepScreenOn = true; let promise = windowClass.setKeepScreenOn(isKeepScreenOn); promise.then((data) => { console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); }); ``` ### setOutsideTouchable(deprecated) setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void Sets whether the area outside the subwindow is touchable. This API uses an asynchronous callback to return the result. > **NOTE** > > This API cannot be used. > > This API is supported since API version 7 and deprecated since API version 9. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------- | ---- | ---------------- | | touchable | boolean | Yes | Whether the area outside the subwindow is touchable. The value `true` means that such an area is touchable, and `false` means the opposite.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js windowClass.setOutsideTouchable(true, (err, data) => { if (err.code) { console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data)); }) ``` ### setOutsideTouchable(deprecated) setOutsideTouchable(touchable: boolean): Promise<void> Sets whether the area outside the subwindow is touchable. This API uses a promise to return the result. > **NOTE** > > This API cannot be used. > > This API is supported since API version 7 and deprecated since API version 9. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | --------- | ------- | ---- | ---------------- | | touchable | boolean | Yes | Whether the area outside the subwindow is touchable. The value `true` means that such an area is touchable, and `false` means the opposite.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js let promise = windowClass.setOutsideTouchable(true); promise.then((data)=> { console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); }); ``` ### setPrivacyMode7+ setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. When in privacy mode, the window content cannot be captured or recorded. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------- | ---- | -------------------- | | isPrivacyMode | boolean | Yes | Whether the window is in privacy mode.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isPrivacyMode = true; windowClass.setPrivacyMode(isPrivacyMode, (err, data) => { if (err.code) { console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window to privacy mode. Data:' + JSON.stringify(data)); }); ``` ### setPrivacyMode7+ setPrivacyMode(isPrivacyMode: boolean): Promise<void> Sets whether this window is in privacy mode. This API uses a promise to return the result. When in privacy mode, the window content cannot be captured or recorded. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------- | ---- | -------------------- | | isPrivacyMode | boolean | Yes | Whether the window is in privacy mode.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isPrivacyMode = true; let promise = windowClass.setPrivacyMode(isPrivacyMode); promise.then((data)=> { console.info('Succeeded in setting the window to privacy mode. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); }); ``` ### setSnapshotSkip9+ setSnapshotSkip(isSkip: boolean): void Sets whether to ignore this window during screen capturing or recording. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------- | ---- | -------------------- | | isSkip | boolean | Yes | Whether to ignore the window. The default value is `false`.
The value `true` means that the window is ignored, and `false` means the opposite.
| ```js var isSkip = true; windowClass.setSnapshotSkip(isSkip); ``` ### setTouchable7+ setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void Sets whether this window is touchable. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------------------------- | ---- | -------------------- | | isTouchable | boolean | Yes | Whether the window is touchable.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isTouchable = true; windowClass.setTouchable(isTouchable, (err, data) => { if (err.code) { console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window to be touchable. Data:' + JSON.stringify(data)); }); ``` ### setTouchable7+ setTouchable(isTouchable: boolean): Promise<void> Sets whether this window is touchable. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------- | ---- | -------------------- | | isTouchable | boolean | Yes | Whether the window is touchable.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isTouchable = true; let promise = windowClass.setTouchable(isTouchable); promise.then((data)=> { console.info('Succeeded in setting the window to be touchable. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); }); ``` ### setForbidSplitMove9+ setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void Sets whether this window is forbidden to move in split-screen mode. This API uses an asynchronous callback to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------------------------- | ---- | -------------------- | | isForbidSplitMove | boolean | Yes | Whether the window is forbidden to move in split-screen mode.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```js var isForbidSplitMove = true; windowClass.setForbidSplitMove(isForbidSplitMove, (err, data) => { if (err.code) { console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in forbidding window moving in split screen mode. Data:' + JSON.stringify(data)); }); ``` ### setForbidSplitMove9+ setForbidSplitMove(isForbidSplitMove: boolean): Promise<void> Sets whether this window is forbidden to move in split-screen mode. This API uses a promise to return the result. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------- | ---- | -------------------- | | isForbidSplitMove | boolean | Yes | Whether the window is forbidden to move in split-screen mode.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```js var isForbidSplitMove = true; let promise = windowClass.setForbidSplitMove(isForbidSplitMove); promise.then((data)=> { console.info('Succeeded in forbidding window moving in split screen mode. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to forbidd window moving in split screen mode. Cause: ' + JSON.stringify(err)); }); ``` ### snapshot9+ snapshot(callback: AsyncCallback<image.PixelMap>): void Captures this window. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------------------------- | ---- | -------------------- | | callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback used to return the result. | **Example** ```js windowClass.snapshot((err, data) => { if (err.code) { console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); data.release(); // Release the memory in time after the PixelMap is used. }); ``` ### snapshot9+ snapshot(): Promise<image.PixelMap> Captures this window. This API uses a promise to return the result. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the window screenshot.| **Example** ```js let promise = windowClass.snapshot(); promise.then((pixelMap)=> { console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); pixelMap.release(); // Release the memory in time after the PixelMap is used. }).catch((err)=>{ console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); }); ``` ### setBlur9+ setBlur(radius: number): void Blurs this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | radius | number | Yes | Radius of the blur. The value is greater than or equal to 0. The value `0` means that the blur is disabled for the window.| **Example** ```js windowClass.setBlur(4.0); ``` ### setBackdropBlur9+ setBackdropBlur(radius: number): void Blurs the background of this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------------------------------------------------ | | radius | number | Yes | Radius of the blur. The value is greater than or equal to 0. The value `0` means that the blur is disabled for the background of the window.| **Example** ```js windowClass.setBackdropBlur(4.0); ``` ### setBackdropBlurStyle9+ setBackdropBlurStyle(blurStyle: BlurStyle): void Sets the blur style for the background of this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | --------- | --------- | ---- | ---------------------- | | blurStyle | [BlurStyle](#blurstyle9) | Yes | Blur style to set for the background of the window.| **Example** ```js windowClass.setBackdropBlurStyle(window.BlurType.THIN); ``` ### setShadow9+ setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void Sets the shadow for the window borders. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ------------------------------------------------------------ | | radius | number | Yes | Radius of the blur for the borders. The value is greater than or equal to 0. The value `0` means that the shadow is disabled for the window borders.| | color | string | No | Color of the shadow. The value is a hexadecimal color and is case insensitive, for example, `#00FF00` or `#FF00FF00`.| | offsetX | number | No | Offset of the shadow along the x-axis, in pixels. | | offsetY | number | No | Offset of the shadow along the y-axis, in pixels. | **Example** ```js windowClass.setShadow(4.0, '#FF00FF00', 2, 3); ``` ### setCornerRadius9+ setCornerRadius(cornerRadius: number): void Sets the radius of the rounded corners for this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------- | ---- | -------------------- | | radius | number | Yes | Radius of the rounded corners. The value is greater than or equal to 0. The value `0` means that the window does not use rounded corners.| **Example** ```js windowClass.setCornerRadius(4.0); ``` ### opacity9+ opacity(opacity: number): void Sets the opacity for this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------ | ---- | --------------------- | | opacity | number | Yes | Opacity to set. The value ranges from 0.0 to 1.0.| **Example** ```js windowClass.opacity(0.5); ``` ### scale9+ scale(scaleOptions: ScaleOptions): void Sets the scale parameters for this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------ | ------------------------------ | ---- | ---------- | | scaleOptions | [ScaleOptions](#scaleoptions9) | Yes | Scale parameters to set.| **Example** ```js var obj : window.ScaleOptions; obj.x = 2.0; obj.y = 1.0; obj.pivotX = 0.5; obj.pivotY = 0.5; windowClass.scale(obj); ``` ### rotate9+ rotate(rotateOptions: RotateOptions): void Sets the rotation parameters for this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------------- | -------------------------------- | ---- | ---------- | | rotateOptions | [RotateOptions](#rotateoptions9) | Yes | Rotation parameters to set.| **Example** ```js var obj : window.RotateOptions; obj.x = 1.0; obj.y = 1.0; obj.z = 45.0; obj.pivotX = 0.5; obj.pivotY = 0.5; windowClass.rotate(obj); ``` ### translate9+ translate(translateOptions: TranslateOptions): void Sets the translation parameters for this window. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------------- | -------------------------------------- | ---- | ---------- | | translateOptions | [TranslateOptions](#translateoptions9) | Yes | Translation parameters to set.| **Example** ```js var obj : window.TranslateOptions; obj.x = 100.0; obj.y = 0.0; obj.z = 0.0; windowClass.translate(obj); ``` ### getTransitionController9+ getTransitionController(): TransitionController Obtains the transition animation controller. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | ---------------------------------------------- | ---------------- | | [TransitionController](#transitioncontroller9) | Transition animation controller.| **Example** ```js let controller = windowClass.getTransitionController(); // Obtain the transition animation controller. controller.animationForHidden = (context : window.TransitionContext) => { let toWindow = context.toWindow animateTo({ duration: 1000, // Animation duration. tempo: 0.5, // Playback speed. curve: Curve.EaseInOut, // Animation curve. delay: 0, // Animation delay. iterations: 1, // Number of playback times. playMode: PlayMode.Normal // Animation mode. }, () => { var obj : window.TranslateOptions; obj.x = 100.0; obj.y = 0.0; obj.z = 0.0; toWindow.translate(obj); // Set the transition animation. console.info('toWindow translate end'); } ) context.completeTransition(true) console.info('complete transition end'); } windowClass.showWithAnimation((err, data) => { if (err.code) { console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); return; } console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); }) ``` ## WindowStageEventType9+ Describes the lifecycle of a window stage. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Default Value | Description | | ---------- | ------ | ---------- | | FOREGROUND | 1 | The window stage is running in the foreground.| | ACTIVE | 2 | The window stage gains focus.| | INACTIVE | 3 | The window stage loses focus.| | BACKGROUND | 4 | The window stage is running in the background.| ## WindowStage9+ Implements a window manager, which manages each basic window unit, that is, [Window](#window) instance. Before calling any of the following APIs, you must use `[onWindowStageCreate()](js-apis-application-ability.md#abilityonwindowstagecreate)` to create a `WindowStage` instance. ### getMainWindow9+ getMainWindow(callback: AsyncCallback<Window>): void Obtains the main window of this window stage. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | --------------------------------------------- | | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the main window.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); var windowClass = null; windowStage.getMainWindow((err, data) => { if (err.code) { console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); }); } } ``` ### getMainWindow9+ getMainWindow(): Promise<Window> Obtains the main window of this window stage. This API uses a promise to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | -------------------------------- | ------------------------------------------------ | | Promise<[Window](#window)> | Promise used to return the main window.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); var windowClass = null; let promise = windowStage.getMainWindow(); promise.then((data)=> { windowClass = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); }); } } ``` ### createSubWindow9+ createSubWindow(name: string, callback: AsyncCallback<Window>): void Creates a subwindow for this window stage. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | --------------------------------------------- | | name | String | Yes | Name of the subwindow. | | callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); var windowClass = null; windowStage.createSubWindow("mySubWindow", (err, data) => { if (err.code) { console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); windowClass.resetSize(500, 1000); }); } } ``` ### createSubWindow9+ createSubWindow(name: string): Promise<Window> Creates a subwindow for this window stage. This API uses a promise to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------------- | | name | String | Yes | Name of the subwindow.| **Return value** | Type | Description | | -------------------------------- | ------------------------------------------------ | | Promise<[Window](#window)> | Promise used to return the subwindow.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); var windowClass = null; let promise = windowStage.createSubWindow("mySubWindow"); promise.then((data)=> { windowClass = data; console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); }) } } ``` ### getSubWindow9+ getSubWindow(callback: AsyncCallback<Array<Window>>): void Obtains all the subwindows of this window stage. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | | callback | AsyncCallback<Array<[Window](#window)>> | Yes | Callback used to return all the subwindows.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); var windowClass = null; windowStage.getSubWindow((err, data) => { if (err.code) { console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); return; } windowClass = data; console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); }); } } ``` ### getSubWindow9+ getSubWindow(): Promise<Array<Window>> Obtains all the subwindows of this window stage. This API uses a promise to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Return value** | Type | Description | | --------------------------------------------- | ---------------------------------------------------- | | Promise<Array<[Window](#window)>> | Promise used to return all the subwindows.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); var windowClass = null; let promise = windowStage.getSubWindow(); promise.then((data)=> { windowClass = data; console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); }) } } ``` ### loadContent9+ loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void Loads content from a page associated with a local storage to the main window in this window stage. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Path of the page from which the content will be loaded. | | storage | [LocalStorage](../../ui/ui-ts-local-storage.md) | Yes | A storage unit, which provides storage for variable state properties and non-variable state properties of an application.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { storage : LocalStorage onWindowStageCreate(windowStage) { this.storage = new LocalStorage(); this.storage.setOrCreate("storageSimpleProp",121); console.log('onWindowStageCreate'); windowStage.loadContent("pages/page2",this.storage,(err, data) => { if (err.code) { console.error('Failed to load the content. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }); } } ``` ### loadContent9+ loadContent(path: string, storage?: LocalStorage): Promise<void> Loads content from a page associated with a local storage to the main window in this window stage. This API uses a promise to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | | path | string | Yes | Path of the page from which the content will be loaded. | | storage | [LocalStorage](../../ui/ui-ts-local-storage.md) | No | A storage unit, which provides storage for variable state properties and non-variable state properties of an application.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { storage : LocalStorage onWindowStageCreate(windowStage) { this.storage = new LocalStorage(); this.storage.setOrCreate("storageSimpleProp",121); console.log('onWindowStageCreate'); var windowClass = null; let promise = windowStage.loadContent("pages/page2",this.storage); promise.then((data)=> { windowClass = data; console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }).catch((err)=>{ console.error('Failed to load the content. Cause:' + JSON.stringify(err)); }) } } ``` ### loadContent9+ loadContent(path: string, callback: AsyncCallback<void>): void Loads content from a page to this window stage. This API uses an asynchronous callback to return the result. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------- | | path | string | Yes | Path of the page from which the content will be loaded.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); windowStage.loadContent("pages/page2", (err, data) => { if (err.code) { console.error('Failed to load the content. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); }); } } ``` ### on('windowStageEvent')9+ on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void Enables listening for window stage lifecycle changes. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `windowStageEvent`, indicating the window stage lifecycle change event.| | callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | Yes | Callback used to return the window stage lifecycle state. | **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); windowStage.on('windowStageEvent', (data) => { console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + JSON.stringify(data)); }); } } ``` ### off('windowStageEvent')9+ off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void Disables listening for window stage lifecycle changes. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | string | Yes | Event type. The value is fixed at `windowStageEvent`, indicating the window stage lifecycle change event.| | callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | No | Callback used to return the window stage lifecycle state. | **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); windowStage.off('windowStageEvent'); } } ``` ### disableWindowDecor()9+ disableWindowDecor(): void Disables window decorators. **Model restriction**: This API can be used only in the stage model. **System API**: This is a system API. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('disableWindowDecor'); windowStage.disableWindowDecor(); } } ``` ### setShowOnLockScreen()9+ setShowOnLockScreen(showOnLockScreen: boolean): void Sets whether to display the window of the application on the lock screen. **System API**: This is a system API. **Model restriction**: This API can be used only in the stage model. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ---------------- | ------- | ---- | ---------------------------- | | showOnLockScreen | boolean | Yes | Whether to display the window on the lock screen.| **Example** ```ts import Ability from '@ohos.application.Ability'; class myAbility extends Ability { onWindowStageCreate(windowStage) { console.log('onWindowStageCreate'); windowStage.setShowOnLockScreen(true); } } ``` ## TransitionContext9+ Provides the context for the transition animation. **System API**: This is a system API. ### toWindow9+ **System capability**: SystemCapability.WindowManager.WindowManager.Core | Name | Type | Readable| Writable| Description | | -------- | ----------------- | ---- | ---- | ---------------- | | toWindow | [Window](#window) | Yes | Yes | Target window to display the animation.| ### completeTransition9+ completeTransition(isCompleted: boolean): void Completes the transition. This API must be called after [animateTo()](../arkui-ts/ts-explicit-animation.md) is executed. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ----------- | ------- | ---- | ------------------------------------------------------------ | | isCompleted | boolean | Yes | Whether the transition is complete. The value `true` means that the transition is complete, and `false` means the opposite.| **Example** ```js let controller = windowClass.getTransitionController(); controller.animationForShown = (context : window.TransitionContext) => { let toWindow = context.toWindow animateTo({ duration: 1000, // Animation duration. tempo: 0.5, // Playback speed. curve: Curve.EaseInOut, // Animation curve. delay: 0, // Animation delay. iterations: 1, // Number of playback times. playMode: PlayMode.Normal // Animation mode. }, () => { var obj : window.TranslateOptions; obj.x = 100.0; obj.y = 0.0; obj.z = 0.0; toWindow.translate(obj); console.info('toWindow translate end'); } ) context.completeTransition(true) console.info('complete transition end'); } ``` ## TransitionController9+ Implements the transition animation controller. **System API**: This is a system API. ### animationForShown9+ animationForShown(context: TransitionContext): void Customizes the animation when the window is shown. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ---------------------------------------- | ---- | -------------------- | | context | [TransitionContext](#transitioncontext9) | Yes | Context of the transition animation.| **Example** ```js let controller = windowClass.getTransitionController(); controller.animationForShown = (context : window.TransitionContext) => { let toWindow = context.toWindow animateTo({ duration: 1000, // Animation duration. tempo: 0.5, // Playback speed. curve: Curve.EaseInOut, // Animation curve. delay: 0, // Animation delay. iterations: 1, // Number of playback times. playMode: PlayMode.Normal // Animation mode. }, () => { var obj : window.TranslateOptions; obj.x = 100.0; obj.y = 0.0; obj.z = 0.0; toWindow.translate(obj); console.info('toWindow translate end'); } ) context.completeTransition(true) console.info('complete transition end'); } ``` ### animationForHidden9+ animationForHidden(context: TransitionContext): void Customizes the animation when the window is hidden. **System capability**: SystemCapability.WindowManager.WindowManager.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ---------------------------------------- | ---- | -------------------- | | context | [TransitionContext](#transitioncontext9) | Yes | Context of the transition animation.| **Example** ```js let controller = windowClass.getTransitionController(); controller.animationForHidden = (context : window.TransitionContext) => { let toWindow = context.toWindow animateTo({ duration: 1000, // Animation duration. tempo: 0.5, // Playback speed. curve: Curve.EaseInOut, // Animation curve. delay: 0, // Animation delay. iterations: 1, // Number of playback times. playMode: PlayMode.Normal // Animation mode. }, () => { var obj : window.TranslateOptions; obj.x = 100.0; obj.y = 0.0; obj.z = 0.0; toWindow.translate(obj); console.info('toWindow translate end'); } ) context.completeTransition(true) console.info('complete transition end'); } ```