1# @ohos.window (Window) 2 3The **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. 4 5This module provides the following common window-related functions: 6 7- [Window](#window): the current window instance, which is the basic unit managed by the window manager. 8- [WindowStage](#windowstage9): window manager that manages windows. 9 10> **NOTE** 11> 12> 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. 13 14## Modules to Import 15 16```ts 17import window from '@ohos.window'; 18``` 19 20## WindowType<sup>7+</sup> 21 22Enumerates the window types. 23 24**System capability**: SystemCapability.WindowManager.WindowManager.Core 25 26| Name | Value| Description | 27| ----------------- | ------ | ------------------ | 28| TYPE_APP | 0 | Application subwindow.<br>**Model restriction**: This API can be used only in the FA model.| 29| TYPE_SYSTEM_ALERT | 1 | System alert window.| 30| TYPE_INPUT_METHOD<sup>9+</sup> | 2 | Input method window.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 31| TYPE_STATUS_BAR<sup>9+</sup> | 3 | Status bar.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 32| TYPE_PANEL<sup>9+</sup> | 4 | Notification panel.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 33| TYPE_KEYGUARD<sup>9+</sup> | 5 | Lock screen.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 34| TYPE_VOLUME_OVERLAY<sup>9+</sup> | 6 | Volume bar.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 35| TYPE_NAVIGATION_BAR<sup>9+</sup> | 7 | Navigation bar.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 36| TYPE_FLOAT<sup>9+</sup> | 8 | Floating window.<br>**Model restriction**: This API can be used only in the stage model.<br>**Required permissions**: ohos.permission.SYSTEM_FLOAT_WINDOW| 37| TYPE_WALLPAPER<sup>9+</sup> | 9 | Wallpaper.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 38| TYPE_DESKTOP<sup>9+</sup> | 10 | Home screen.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 39| TYPE_LAUNCHER_RECENT<sup>9+</sup> | 11 | Recent tasks screen.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 40| TYPE_LAUNCHER_DOCK<sup>9+</sup> | 12 | Dock bar on the home screen.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 41| TYPE_VOICE_INTERACTION<sup>9+</sup> | 13 | Voice assistant.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 42| TYPE_POINTER<sup>9+</sup> | 14 | Mouse.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 43| TYPE_FLOAT_CAMERA<sup>9+</sup> | 15 | Floating camera window.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 44| TYPE_DIALOG<sup>10+</sup> | 16 | Modal window.<br>**Model restriction**: This API can be used only in the stage model.| 45| TYPE_SCREENSHOT<sup>9+</sup> | 17 | Screenshot window.<br>**Model restriction**: This API can be used only in the stage model.<br>**System API**: This is a system API.| 46 47## Configuration<sup>9+</sup> 48 49Defines the parameters for creating a subwindow or system window. 50 51**System capability**: SystemCapability.WindowManager.WindowManager.Core 52 53| Name| Type| Mandatory| Description | 54| ---------- | -------------------------- | -- |-----------------------------------------------------------------------------| 55| name | string | Yes| Name of the window. | 56| windowType | [WindowType](#windowtype7) | Yes| Type of the window. | 57| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | No| Current application context. If no value is passed, no context is used.<br>You do not need to set this parameter to create a subwindow in the FA model or a system window in the stage model.| 58| displayId | number | No| ID of the current physical screen. If no value is passed, the default value **-1** is used. The value must be an integer. | 59| parentId | number | No| ID of the parent window. If no value is passed, the default value **-1** is used. The value must be an integer. | 60 61## AvoidAreaType<sup>7+</sup> 62 63Enumerates the types of the area where the window cannot be displayed. 64 65**System capability**: SystemCapability.WindowManager.WindowManager.Core 66 67| Name | Value | Description | 68| -------------------------------- | ---- | ------------------------------------------------------------ | 69| TYPE_SYSTEM | 0 | Default area of the system. Generally, the status bar and navigation bar are included. The default area may vary according to the device in use.| 70| TYPE_CUTOUT | 1 | Notch. | 71| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | Gesture area. | 72| TYPE_KEYBOARD<sup>9+</sup> | 3 | Soft keyboard area. | 73 74## WindowMode<sup>7+</sup> 75 76Enumerates the window modes. 77 78**System API**: This is a system API. 79 80**System capability**: SystemCapability.WindowManager.WindowManager.Core 81 82| Name | Value | Description | 83| ---------- | ---- | ----------------------------- | 84| UNDEFINED | 1 | The window mode is not defined by the application. | 85| FULLSCREEN | 2 | The application is displayed in full screen. | 86| PRIMARY | 3 | The application is displayed in the primary window in split-screen mode. | 87| SECONDARY | 4 | The application is displayed in the secondary window in split-screen mode. | 88| FLOATING | 5 | The application is displayed in a floating window.| 89 90## WindowLayoutMode<sup>9+</sup> 91 92Enumerates the window layout modes. 93 94**System API**: This is a system API. 95 96**System capability**: SystemCapability.WindowManager.WindowManager.Core 97 98| Name | Value | Description | 99| ---------- | ---- | ----------------------------- | 100| WINDOW_LAYOUT_MODE_CASCADE | 0 | Cascade mode. | 101| WINDOW_LAYOUT_MODE_TILE | 1 | Tile mode. | 102 103## SystemBarProperties 104 105Describes the properties of the status bar and navigation bar. 106 107**System capability**: SystemCapability.WindowManager.WindowManager.Core 108 109| Name | Type| Mandatory| Description | 110| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 111| statusBarColor | string | No | Background color of the status bar. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**. The default value is **#0x66000000**.| 112| isStatusBarLightIcon<sup>7+</sup> | boolean | No | Whether any icon on the status bar is highlighted. The value **true** means that the icon is highlighted, and **false** means the opposite. The default value is **false**.| 113| statusBarContentColor<sup>8+</sup> | string | No | Color of the text on the status bar. After this property is set, the setting of **isStatusBarLightIcon** is invalid. The default value is **0xE5FFFFFF**.| 114| navigationBarColor | string | No | Background color of the navigation bar. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**. The default value is **#0x66000000**.| 115| isNavigationBarLightIcon<sup>7+</sup> | boolean | No | Whether any icon on the navigation bar is highlighted. The value **true** means that the icon is highlighted, and **false** means the opposite. The default value is **false**.| 116| navigationBarContentColor<sup>8+</sup> | string | No | Color of the text on the navigation bar. After this property is set, the setting of **isNavigationBarLightIcon** is invalid. The default value is **0xE5FFFFFF**.| 117 118## Orientation<sup>9+</sup> 119 120Enumerates the window orientations. 121 122**System capability**: SystemCapability.WindowManager.WindowManager.Core 123 124| Name | Value | Description | 125| ------------------------------------- | ---- | ----------------------------- | 126| UNSPECIFIED | 0 | Unspecified. The orientation is determined by the system.| 127| PORTRAIT | 1 | Portrait. | 128| LANDSCAPE | 2 | Landscape. | 129| PORTRAIT_INVERTED | 3 | Reverse portrait. | 130| LANDSCAPE_INVERTED | 4 | Reverse landscape.| 131| AUTO_ROTATION | 5 | Auto rotation.| 132| AUTO_ROTATION_PORTRAIT | 6 | Auto rotation in the vertical direction.| 133| AUTO_ROTATION_LANDSCAPE | 7 | Auto rotation in the horizontal direction.| 134| AUTO_ROTATION_RESTRICTED | 8 | Switched-determined auto rotation.| 135| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | Switched-determined auto rotation in the vertical direction.| 136| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | Switched-determined auto rotation in the horizontal direction.| 137| LOCKED | 11 | Locked.| 138 139## BlurStyle<sup>9+</sup> 140 141Enumerates the window blur styles. 142 143**System API**: This is a system API. 144 145**System capability**: SystemCapability.WindowManager.WindowManager.Core 146 147| Name | Value | Description | 148| ------- | ---- | -------------------- | 149| OFF | 0 | Blur disabled. | 150| THIN | 1 | Thin blur.| 151| REGULAR | 2 | Regular blur.| 152| THICK | 3 | Thick blur.| 153 154## SystemBarRegionTint<sup>8+</sup> 155 156Describes the callback for a single system bar. 157 158**System API**: This is a system API. 159 160**System capability**: SystemCapability.WindowManager.WindowManager.Core 161 162| Name | Type | Readable| Writable| Description | 163| --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | 164| type | [WindowType](#windowtype7) | Yes | No | Type of the system bar whose properties are changed. Only the status bar and navigation bar are supported.| 165| isEnable | boolean | Yes | No | Whether the system bar is displayed. The value **true** means that the system bar is displayed, and **false** means the opposite.| 166| region | [Rect](#rect7) | Yes | No | Current position and size of the system bar. | 167| backgroundColor | string | Yes | No | Background color of the system bar. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**.| 168| contentColor | string | Yes | No | Color of the text on the system bar. | 169 170## SystemBarTintState<sup>8+</sup> 171 172Describes the callback for the current system bar. 173 174**System API**: This is a system API. 175 176**System capability**: SystemCapability.WindowManager.WindowManager.Core 177 178| Name | Type | Readable| Writable| Description | 179| ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- | 180| displayId | number | Yes | No | ID of the current physical screen. The value must be an integer. | 181| regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | Yes | No | All system bar information that has been changed.| 182 183## Rect<sup>7+</sup> 184 185Describes the rectangular area of the window. 186 187**System capability**: SystemCapability.WindowManager.WindowManager.Core 188 189| Name | Type| Readable| Writable| Description | 190| ------ | -------- | ---- | ---- | ------------------ | 191| left | number | Yes | Yes | Left boundary of the rectangle, in pixels. The value must be an integer.| 192| top | number | Yes | Yes | Top boundary of the rectangle, in pixels. The value must be an integer.| 193| width | number | Yes | Yes | Width of the rectangle, in pixels. The value must be an integer.| 194| height | number | Yes | Yes | Height of the rectangle, in pixels. The value must be an integer.| 195 196## AvoidArea<sup>7+</sup> 197 198Describes the area where the window cannot be displayed. 199 200**System capability**: SystemCapability.WindowManager.WindowManager.Core 201 202| Name | Type | Readable| Writable| Description | 203| ---------- | ------------- | ---- | ---- | ------------------ | 204| visible<sup>9+</sup> | boolean | Yes | Yes | Whether the window can be displayed in the area. The value **true** means that the window can be displayed in the area, and **false** means the opposite.| 205| leftRect | [Rect](#rect7) | Yes | Yes | Rectangle on the left of the screen.| 206| topRect | [Rect](#rect7) | Yes | Yes | Rectangle at the top of the screen.| 207| rightRect | [Rect](#rect7) | Yes | Yes | Rectangle on the right of the screen.| 208| bottomRect | [Rect](#rect7) | Yes | Yes | Rectangle at the bottom of the screen.| 209 210## Size<sup>7+</sup> 211 212Describes the window size. 213 214**System capability**: SystemCapability.WindowManager.WindowManager.Core 215 216| Name | Type| Readable| Writable| Description | 217| ------ | -------- | ---- | ---- | ---------- | 218| width | number | Yes | Yes | Window width, in pixels. The value must be an integer.| 219| height | number | Yes | Yes | Window height, in pixels. The value must be an integer.| 220 221## WindowProperties 222 223Describes the window properties. 224 225**System capability**: SystemCapability.WindowManager.WindowManager.Core 226 227| Name | Type | Readable| Writable| Description | 228| ------------------------------------- | ------------------------- | ---- | ---- |--------------------------------------------------------------------------------------------------------| 229| windowRect<sup>7+</sup> | [Rect](#rect7) | Yes | Yes | Window size. | 230| type<sup>7+</sup> | [WindowType](#windowtype7) | Yes | Yes | Window type. | 231| isFullScreen | boolean | Yes | Yes | Whether the window is displayed in full-screen mode. The default value is **false**. The value **true** means that the window is displayed in full-screen mode, and **false** means the opposite. | 232| isLayoutFullScreen<sup>7+</sup> | boolean | Yes | Yes | Whether the window layout is in full-screen mode (whether the window is immersive). The default value is **false**. The value **true** means that the window is immersive, and **false** means the opposite. | 233| focusable<sup>7+</sup> | boolean | Yes | No | Whether the window can gain focus. The default value is **true**. The value **true** means that the window can gain focus, and **false** means the opposite. | 234| touchable<sup>7+</sup> | boolean | Yes | No | Whether the window is touchable. The default value is **true**. The value **true** means that the window is touchable, and **false** means the opposite. | 235| brightness | number | Yes | Yes | Screen brightness. The value is a floating point number in the range [0.0, 1.0], and the value **1.0** means the brightest. If no value is passed, the brightness follows the system. In this case, the obtained brightness value is **-1**. | 236| dimBehindValue<sup>(deprecated)</sup> | number | Yes | Yes | Dimness of the window that is not on top. The value is a floating point number in the range [0.0, 1.0], and the value **1.0** means the dimmest.<br>**NOTE**<br>This property is supported since API version 7 and deprecated since API version 9. | 237| isKeepScreenOn | boolean | Yes | Yes | Whether the screen is always on. The default value is **false**. The value **true** means that the screen is always on, and **false** means the opposite. | 238| isPrivacyMode<sup>7+</sup> | boolean | Yes | Yes | Whether the window is in privacy mode. The default value is **false**. The value **true** means that the window is in privacy mode, and **false** means the opposite. | 239| isRoundCorner<sup>(deprecated)</sup> | boolean | Yes | Yes | Whether the window has rounded corners. The default value is **false**. The value **true** means that the window has rounded corners, and **false** means the opposite.<br>**NOTE**<br>This property is supported since API version 7 and deprecated since API version 9. | 240| isTransparent<sup>7+</sup> | boolean | Yes | Yes | Whether the window is transparent. The default value is **false**. The value **true** means that the window is transparent, and **false** means the opposite. | 241| id<sup>9+</sup> | number | Yes | No | Window ID. The default value is **0**. The value must be an integer. | 242 243## ColorSpace<sup>8+</sup> 244 245Enumerates the color spaces. 246 247**System capability**: SystemCapability.WindowManager.WindowManager.Core 248 249| Name | Value| Description | 250| ---------- | ------ | -------------- | 251| DEFAULT | 0 | Default SRGB gamut.| 252| WIDE_GAMUT | 1 | Wide-gamut. | 253 254## ScaleOptions<sup>9+</sup> 255 256Describes the scale parameters. 257 258**System API**: This is a system API. 259 260**System capability**: SystemCapability.WindowManager.WindowManager.Core 261 262| Name | Type| Readable| Writable| Description | 263| ------ | -------- | ---- | ---- |--------------------------------------------| 264| x | number | No | Yes | Scale factor along the x-axis. The value is a floating point number, and the default value is **1.0**. | 265| y | number | No | Yes | Scale factor along the y-axis. The value is a floating point number, and the default value is **1.0**. | 266| pivotX | number | No | Yes | X coordinate of the scale center. The value is a floating point number in the range [0.0, 1.0], and the default value is **0.5**.| 267| pivotY | number | No | Yes | Y coordinate of the scale center. The value is a floating point number in the range [0.0, 1.0], and the default value is **0.5**.| 268 269## RotateOptions<sup>9+</sup> 270 271Describes the rotation parameters. 272 273**System API**: This is a system API. 274 275**System capability**: SystemCapability.WindowManager.WindowManager.Core 276 277| Name | Type| Readable| Writable| Description | 278| ------ | -------- | ---- | ---- |---------------------------------------------| 279| x | number | No | Yes | Rotation angle around the x-axis. The value is a floating point number, and the default value is **0.0**. | 280| y | number | No | Yes | Rotation angle around the y-axis. The value is a floating point number, and the default value is **0.0**. | 281| z | number | No | Yes | Rotation angle around the z-axis. The value is a floating point number, and the default value is **0.0**. | 282| pivotX | number | No | Yes | X coordinate of the rotation center. The value is a floating point number in the range [0.0, 1.0], and the default value is **0.5**.| 283| pivotY | number | No | Yes | Y coordinate of the rotation center. The value is a floating point number in the range [0.0, 1.0], and the default value is **0.5**. | 284 285## TranslateOptions<sup>9+</sup> 286 287Describes the translation parameters. 288 289**System API**: This is a system API. 290 291**System capability**: SystemCapability.WindowManager.WindowManager.Core 292 293| Name| Type| Readable| Writable| Description | 294| ---- | -------- | ---- | ---- | ---------------------------- | 295| x | number | No | Yes | Distance to translate along the x-axis. The value is a floating point number, and the default value is **0.0**.| 296| y | number | No | Yes | Distance to translate along the y-axis. The value is a floating point number, and the default value is **0.0**.| 297| z | number | No | Yes | Distance to translate along the z-axis. The value is a floating point number, and the default value is **0.0**.| 298 299## WindowEventType<sup>10+</sup> 300 301Enumerates the window lifecycle states. 302 303**System capability**: SystemCapability.WindowManager.WindowManager.Core 304 305| Name | Value| Description | 306| ---------- | ------ | ---------- | 307| WINDOW_SHOWN | 1 | The window is running in the foreground.| 308| WINDOW_ACTIVE | 2 | The window gains focus.| 309| WINDOW_INACTIVE | 3 | The window loses focus.| 310| WINDOW_HIDDEN | 4 | The window is running in the background.| 311 312## window.createWindow<sup>9+</sup> 313 314createWindow(config: Configuration, callback: AsyncCallback<Window>): void 315 316Creates a subwindow or system window. This API uses an asynchronous callback to return the result. 317 318**System capability**: SystemCapability.WindowManager.WindowManager.Core 319 320**Parameters** 321 322| Name| Type| Mandatory| Description| 323| -------- | -------------------------------------- | -- | --------------------------------- | 324| config | [Configuration](#configuration9) | Yes| Parameters used for creating the window. | 325| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the window created.| 326 327**Error codes** 328 329For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 330 331| ID| Error Message| 332| ------- | -------------------------------- | 333| 1300001 | Repeated operation. | 334| 1300006 | This window context is abnormal. | 335| 1300008 | The operation is on invalid display. | 336| 1300009 | The parent window is invalid. | 337 338**Example** 339 340```ts 341import { BusinessError } from '@ohos.base'; 342 343let windowClass: window.Window | null = null; 344let config: window.Configuration = { 345 name: "alertWindow", 346 windowType: window.WindowType.TYPE_SYSTEM_ALERT, 347 ctx: this.context 348}; 349try { 350 window.createWindow(config, (err: BusinessError, data) => { 351 const errCode: number = err.code; 352 if (errCode) { 353 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 354 return; 355 } 356 windowClass = data; 357 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 358 windowClass.resetSize(500, 1000); 359 }); 360} catch (exception) { 361 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 362} 363``` 364 365## window.createWindow<sup>9+</sup> 366 367createWindow(config: Configuration): Promise<Window> 368 369Creates a subwindow or system window. This API uses a promise to return the result. 370 371**System capability**: SystemCapability.WindowManager.WindowManager.Core 372 373**Parameters** 374 375| Name| Type| Mandatory| Description| 376| ------ | -------------------------------- | -- | ------------------ | 377| config | [Configuration](#configuration9) | Yes| Parameters used for creating the window.| 378 379**Return value** 380 381| Type| Description| 382| -------------------------------- | ------------------------------------ | 383| Promise<[Window](#window)> | Promise used to return the window created.| 384 385**Error codes** 386 387For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 388 389| ID| Error Message| 390| ------- | -------------------------------- | 391| 1300001 | Repeated operation. | 392| 1300006 | This window context is abnormal. | 393| 1300008 | The operation is on invalid display. | 394| 1300009 | The parent window is invalid. | 395 396**Example** 397 398```ts 399import { BusinessError } from '@ohos.base'; 400 401let windowClass: window.Window | null = null; 402let config: window.Configuration = { 403 name: "alertWindow", 404 windowType: window.WindowType.TYPE_SYSTEM_ALERT, 405 ctx: this.context 406}; 407try { 408 let promise = window.createWindow(config); 409 promise.then((data) => { 410 windowClass = data; 411 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 412 }).catch((err: BusinessError) => { 413 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 414 }); 415} catch (exception) { 416 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 417} 418``` 419 420## window.findWindow<sup>9+</sup> 421 422findWindow(name: string): Window 423 424Finds a window based on the name. 425 426**System capability**: SystemCapability.WindowManager.WindowManager.Core 427 428**Parameters** 429 430| Name| Type | Mandatory| Description | 431| ------ | ------ | ---- | -------- | 432| name | string | Yes | Window ID.| 433 434**Return value** 435 436| Type| Description| 437| ----------------- | ------------------- | 438| [Window](#window) | Window found.| 439 440**Error codes** 441 442For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 443 444| ID| Error Message| 445| ------- | -------------------------------- | 446| 1300002 | This window state is abnormal. | 447 448**Example** 449 450```ts 451let windowClass: window.Window | null = null; 452try { 453 windowClass = window.findWindow('alertWindow'); 454} catch (exception) { 455 console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception)); 456} 457``` 458 459## window.getLastWindow<sup>9+</sup> 460 461getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 462 463Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 464 465**System capability**: SystemCapability.WindowManager.WindowManager.Core 466 467**Parameters** 468 469| Name| Type| Mandatory| Description| 470| -------- | -------------------------------------- | -- | ---------------------------------------- | 471| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes| Current application context.| 472| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the top window obtained.| 473 474**Error codes** 475 476For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 477 478| ID| Error Message| 479| ------- | -------------------------------- | 480| 1300002 | This window state is abnormal. | 481| 1300006 | This window context is abnormal. | 482 483**Example** 484 485```ts 486import { BusinessError } from '@ohos.base'; 487 488let windowClass: window.Window | null = null; 489try { 490 window.getLastWindow(this.context, (err: BusinessError, data) => { 491 const errCode: number = err.code; 492 if (errCode) { 493 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 494 return; 495 } 496 windowClass = data; 497 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 498 }); 499} catch (exception) { 500 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 501} 502``` 503 504## window.getLastWindow<sup>9+</sup> 505 506getLastWindow(ctx: BaseContext): Promise<Window> 507 508Obtains the top window of the current application. This API uses a promise to return the result. 509 510**System capability**: SystemCapability.WindowManager.WindowManager.Core 511 512**Parameters** 513 514| Name| Type| Mandatory| Description| 515| ------ | ----------- | ---- | ------------------------------------------------------------ | 516| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current application context.| 517 518**Return value** 519 520| Type| Description| 521| -------------------------------- | ------------------------------------------- | 522| Promise<[Window](#window)> | Promise used to return the top window obtained.| 523 524**Error codes** 525 526For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 527 528| ID| Error Message| 529| ------- | -------------------------------- | 530| 1300002 | This window state is abnormal. | 531| 1300006 | This window context is abnormal. | 532 533**Example** 534 535```ts 536import { BusinessError } from '@ohos.base'; 537 538let windowClass: window.Window | null = null; 539try { 540 let promise = window.getLastWindow(this.context); 541 promise.then((data) => { 542 windowClass = data; 543 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 544 }).catch((err: BusinessError) => { 545 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 546 }); 547} catch (exception) { 548 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 549} 550``` 551 552## window.minimizeAll<sup>9+</sup> 553minimizeAll(id: number, callback: AsyncCallback<void>): void 554 555Minimizes all windows on a display. This API uses an asynchronous callback to return the result. 556 557**System API**: This is a system API. 558 559**System capability**: SystemCapability.WindowManager.WindowManager.Core 560 561**Parameters** 562 563| Name | Type | Mandatory| Description | 564| -------- | ------------------------- | ---- | -------------- | 565| id | number | Yes | ID of the [display](js-apis-display.md#display). The value must be an integer.| 566| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 567 568**Error codes** 569 570For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 571 572| ID| Error Message| 573| ------- | -------------------------------------------- | 574| 1300003 | This window manager service works abnormally. | 575 576**Example** 577 578```ts 579import display from '@ohos.display' 580import { BusinessError } from '@ohos.base'; 581 582let displayClass: display.Display | null = null; 583try { 584 displayClass = display.getDefaultDisplaySync(); 585 586 try { 587 window.minimizeAll(displayClass.id, (err: BusinessError) => { 588 const errCode: number = err.code; 589 if (errCode) { 590 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); 591 return; 592 } 593 console.info('Succeeded in minimizing all windows.'); 594 }); 595 } catch (exception) { 596 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception)); 597 } 598} catch (exception) { 599 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 600} 601``` 602 603## window.minimizeAll<sup>9+</sup> 604minimizeAll(id: number): Promise<void> 605 606Minimizes all windows on a display. This API uses a promise to return the result. 607 608**System API**: This is a system API. 609 610**System capability**: SystemCapability.WindowManager.WindowManager.Core 611 612**Parameters** 613 614| Name | Type | Mandatory| Description | 615| -------- | ------------------------- | ---- | -------------- | 616| id | number | Yes | ID of the [display](js-apis-display.md#display). The value must be an integer.| 617 618**Return value** 619 620| Type | Description | 621| ------------------- | ------------------------- | 622| Promise<void> | Promise that returns no value.| 623 624**Error codes** 625 626For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 627 628| ID| Error Message| 629| ------- | -------------------------------------------- | 630| 1300003 | This window manager service works abnormally. | 631 632**Example** 633 634```ts 635import display from '@ohos.display' 636import { BusinessError } from '@ohos.base'; 637 638let displayClass: display.Display | null = null; 639try { 640 displayClass = display.getDefaultDisplaySync(); 641 642 try { 643 let promise = window.minimizeAll(displayClass.id); 644 promise.then(() => { 645 console.info('Succeeded in minimizing all windows.'); 646 }).catch((err: BusinessError) => { 647 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); 648 }); 649 } catch (exception) { 650 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception)); 651 } 652} catch (exception) { 653 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 654} 655``` 656 657## window.toggleShownStateForAllAppWindows<sup>9+</sup> 658toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void 659 660Hides or restores the application's windows during quick multi-window switching. This API uses an asynchronous callback to return the result. 661 662**System API**: This is a system API. 663 664**System capability**: SystemCapability.WindowManager.WindowManager.Core 665 666**Parameters** 667 668| Name | Type | Mandatory| Description | 669| -------- | ------------------------- | ---- | -------------- | 670| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 671 672**Error codes** 673 674For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 675 676| ID| Error Message| 677| ------- | -------------------------------------------- | 678| 1300003 | This window manager service works abnormally. | 679 680**Example** 681 682```ts 683import { BusinessError } from '@ohos.base'; 684 685window.toggleShownStateForAllAppWindows((err: BusinessError) => { 686 const errCode: number = err.code; 687 if (errCode) { 688 console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); 689 return; 690 } 691 console.info('Succeeded in toggling shown state for all app windows.'); 692}); 693``` 694 695## window.toggleShownStateForAllAppWindows<sup>9+</sup> 696toggleShownStateForAllAppWindows(): Promise<void> 697 698Hides or restores the application's windows during quick multi-window switching. This API uses a promise to return the result. 699 700**System API**: This is a system API. 701 702**System capability**: SystemCapability.WindowManager.WindowManager.Core 703 704**Return value** 705 706| Type | Description | 707| ------------------- | ------------------------- | 708| Promise<void> | Promise that returns no value.| 709 710**Error codes** 711 712For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 713 714| ID| Error Message| 715| ------- | -------------------------------------------- | 716| 1300003 | This window manager service works abnormally. | 717 718**Example** 719 720```ts 721import { BusinessError } from '@ohos.base'; 722 723let promise = window.toggleShownStateForAllAppWindows(); 724promise.then(() => { 725 console.info('Succeeded in toggling shown state for all app windows.'); 726}).catch((err: BusinessError) => { 727 console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); 728}); 729``` 730 731## window.setWindowLayoutMode<sup>9+</sup> 732setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void 733 734Sets the window layout mode. This API uses an asynchronous callback to return the result. 735 736**System API**: This is a system API. 737 738**System capability**: SystemCapability.WindowManager.WindowManager.Core 739 740**Parameters** 741 742| Name | Type | Mandatory| Description | 743| -------- | ------------------------- | ---- | -------------- | 744| mode | [WindowLayoutMode](#windowlayoutmode9) | Yes | Window layout mode to set.| 745| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 746 747**Error codes** 748 749For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 750 751| ID| Error Message| 752| ------- | -------------------------------------------- | 753| 1300003 | This window manager service works abnormally. | 754 755**Example** 756 757```ts 758import { BusinessError } from '@ohos.base'; 759 760try { 761 window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (err: BusinessError) => { 762 const errCode: number = err.code; 763 if (errCode) { 764 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); 765 return; 766 } 767 console.info('Succeeded in setting window layout mode.'); 768 }); 769} catch (exception) { 770 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception)); 771} 772``` 773 774## window.setWindowLayoutMode<sup>9+</sup> 775setWindowLayoutMode(mode: WindowLayoutMode): Promise<void> 776 777Sets the window layout mode. This API uses a promise to return the result. 778 779**System API**: This is a system API. 780 781**System capability**: SystemCapability.WindowManager.WindowManager.Core 782 783**Parameters** 784 785| Name | Type | Mandatory| Description | 786| -------- | ------------------------- | ---- | -------------- | 787| mode | [WindowLayoutMode](#windowlayoutmode9) | Yes | Window layout mode to set.| 788 789**Return value** 790 791| Type | Description | 792| ------------------- | ------------------------- | 793| Promise<void> | Promise that returns no value.| 794 795**Error codes** 796 797For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 798 799| ID| Error Message| 800| ------- | -------------------------------------------- | 801| 1300003 | This window manager service works abnormally. | 802 803**Example** 804 805```ts 806import { BusinessError } from '@ohos.base'; 807 808try { 809 let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE); 810 promise.then(() => { 811 console.info('Succeeded in setting window layout mode.'); 812 }).catch((err: BusinessError) => { 813 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); 814 }); 815} catch (exception) { 816 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception)); 817} 818``` 819 820## window.on('systemBarTintChange')<sup>8+</sup> 821 822on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void 823 824Subscribes to the property change event of the status bar and navigation bar. 825 826**System API**: This is a system API. 827 828**System capability**: SystemCapability.WindowManager.WindowManager.Core 829 830**Parameters** 831 832| Name | Type | Mandatory| Description | 833| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 834| type | string | Yes | Event type. The value is fixed at **'systemBarTintChange'**, indicating the property change event of the status bar and navigation bar.| 835| callback | Callback<[SystemBarTintState](#systembartintstate8)> | Yes | Callback used to return the properties of the status bar and navigation bar. | 836 837**Example** 838 839```ts 840try { 841 window.on('systemBarTintChange', (data) => { 842 console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data)); 843 }); 844} catch (exception) { 845 console.error('Failed to enable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception)); 846} 847``` 848 849## window.off('systemBarTintChange')<sup>8+</sup> 850 851off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void 852 853Unsubscribes from the property change event of the status bar and navigation bar. 854 855**System API**: This is a system API. 856 857**System capability**: SystemCapability.WindowManager.WindowManager.Core 858 859**Parameters** 860 861| Name | Type | Mandatory| Description | 862| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 863| type | string | Yes | Event type. The value is fixed at **'systemBarTintChange'**, indicating the property change event of the status bar and navigation bar.| 864| callback | Callback<[SystemBarTintState](#systembartintstate8)> | No | Callback used to return the properties of the status bar and navigation bar. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 865 866**Example** 867 868```ts 869try { 870 window.off('systemBarTintChange'); 871} catch (exception) { 872 console.error('Failed to disable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception)); 873} 874``` 875 876## window.on('gestureNavigationEnabledChange')<sup>10+</sup> 877 878on(type: 'gestureNavigationEnabledChange', callback: Callback<boolean>): void 879 880Subscribes to the gesture navigation status change event. 881 882**System API**: This is a system API. 883 884**System capability**: SystemCapability.WindowManager.WindowManager.Core 885 886**Parameters** 887 888| Name | Type | Mandatory| Description | 889| -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | 890| type | string | Yes | Event type. The value is fixed at **'gestureNavigationEnabledChange'**, indicating the gesture navigation status change event. | 891| callback | Callback<boolean> | Yes | Callback used to return the gesture navigation status. The value **true** means that the gesture navigation status is changed to enabled, and **false** means that the gesture navigation status is changed to disabled.| 892 893**Error codes** 894 895For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 896 897| ID| Error Message| 898| ------- | -------------------------------------------- | 899| 1300002 | This window state is abnormal. | 900| 1300003 | This window manager service works abnormally. | 901 902**Example** 903 904```ts 905try { 906 window.on('gestureNavigationEnabledChange', (data) => { 907 console.info('Succeeded in enabling the listener for gesture navigation status changes. Data: ' + JSON.stringify(data)); 908 }); 909} catch (exception) { 910 console.error('Failed to enable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception)); 911} 912``` 913 914## window.off('gestureNavigationEnabledChange')<sup>10+</sup> 915 916off(type: 'gestureNavigationEnabledChange', callback?: Callback<boolean>): void 917 918Unsubscribes from the gesture navigation status change event. 919 920**System API**: This is a system API. 921 922**System capability**: SystemCapability.WindowManager.WindowManager.Core 923 924**Parameters** 925 926| Name | Type | Mandatory| Description | 927| -------- | ----------------------- | -- | ------------------------------------------------------------ | 928| type | string | Yes| Event type. The value is fixed at **'gestureNavigationEnabledChange'**, indicating the gesture navigation status change event.| 929| callback | Callback<boolean> | No| Callback function that has been used for the subscription. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 930 931**Error codes** 932 933For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 934 935| ID| Error Message| 936| ------- | -------------------------------------------- | 937| 1300002 | This window state is abnormal. | 938| 1300003 | This window manager service works abnormally. | 939 940**Example** 941 942```ts 943try { 944 window.off('gestureNavigationEnabledChange'); 945} catch (exception) { 946 console.error('Failed to disable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception)); 947} 948``` 949 950## window.on('waterMarkFlagChange')<sup>10+</sup> 951 952on(type: 'waterMarkFlagChange', callback: Callback<boolean>): void 953 954Subscribes to the watermark status change event. 955 956**System API**: This is a system API. 957 958**System capability**: SystemCapability.WindowManager.WindowManager.Core 959 960**Parameters** 961 962| Name | Type | Mandatory| Description | 963| -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | 964| type | string | Yes | Event type. The value is fixed at **'waterMarkFlagChange'**, indicating the watermark status change event. | 965| callback | Callback<boolean> | Yes | Callback used to return the watermark status. The value **true** means that the watermark feature is enabled, and **false** means the opposite.| 966 967**Error codes** 968 969For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 970 971| ID| Error Message| 972| ------- | -------------------------------------------- | 973| 1300003 | This window manager service works abnormally. | 974 975**Example** 976 977```ts 978try { 979 window.on('waterMarkFlagChange', (data) => { 980 console.info('Succeeded in enabling the listener for watermark flag changes. Data: ' + JSON.stringify(data)); 981 }); 982} catch (exception) { 983 console.error('Failed to enable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception)); 984} 985``` 986 987## window.off('waterMarkFlagChange')<sup>10+</sup> 988 989off(type: 'waterMarkFlagChange', callback?: Callback<boolean>): void 990 991Unsubscribes from the watermark status change event. 992 993**System API**: This is a system API. 994 995**System capability**: SystemCapability.WindowManager.WindowManager.Core 996 997**Parameters** 998 999| Name | Type | Mandatory| Description | 1000| -------- | ----------------------- | -- | ------------------------------------------------------------ | 1001| type | string | Yes| Event type. The value is fixed at **'waterMarkFlagChange'**, indicating the watermark status change event.| 1002| callback | Callback<boolean> | No| Callback function that has been used for the subscription. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 1003 1004**Error codes** 1005 1006For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1007 1008| ID| Error Message| 1009| ------- | -------------------------------------------- | 1010| 1300003 | This window manager service works abnormally. | 1011 1012**Example** 1013 1014```ts 1015try { 1016 window.off('waterMarkFlagChange'); 1017} catch (exception) { 1018 console.error('Failed to disable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception)); 1019} 1020``` 1021 1022## window.setGestureNavigationEnabled<sup>10+</sup> 1023setGestureNavigationEnabled(enable: boolean, callback: AsyncCallback<void>): void 1024 1025Enables or disables gesture navigation. This API uses an asynchronous callback to return the result. 1026 1027**System API**: This is a system API. 1028 1029**System capability**: SystemCapability.WindowManager.WindowManager.Core 1030 1031**Parameters** 1032 1033| Name | Type | Mandatory| Description | 1034| -------- | ------------------------- | ---- | -------------- | 1035| enable | boolean | Yes | Whether to enable gesture navigation. The value **true** means to enable gesture navigation, and **false** means the opposite.| 1036| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1037 1038**Error codes** 1039 1040For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1041 1042| ID| Error Message| 1043| ------- | --------------------------------------------- | 1044| 1300002 | This window state is abnormal. | 1045| 1300003 | This window manager service works abnormally. | 1046 1047**Example** 1048 1049```ts 1050import { BusinessError } from '@ohos.base'; 1051 1052try { 1053 window.setGestureNavigationEnabled(true, (err: BusinessError) => { 1054 const errCode: number = err.code; 1055 if (errCode) { 1056 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err)); 1057 return; 1058 } 1059 console.info('Succeeded in setting gesture navigation enabled.'); 1060 }); 1061} catch (exception) { 1062 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception)); 1063} 1064``` 1065 1066## window.setGestureNavigationEnabled<sup>10+</sup> 1067setGestureNavigationEnabled(enable: boolean): Promise<void> 1068 1069Enables or disables gesture navigation. This API uses a promise to return the result. 1070 1071**System API**: This is a system API. 1072 1073**System capability**: SystemCapability.WindowManager.WindowManager.Core 1074 1075**Parameters** 1076 1077| Name| Type | Mandatory | Description | 1078| ------ | ------- | ---- | -------------------- | 1079| enable | boolean | Yes | Whether to enable gesture navigation. The value **true** means to enable gesture navigation, and **false** means the opposite.| 1080 1081**Return value** 1082 1083| Type | Description | 1084| ------------------- | ------------------------- | 1085| Promise<void> | Promise that returns no value.| 1086 1087**Error codes** 1088 1089For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1090 1091| ID| Error Message| 1092| ------- | -------------------------------------------- | 1093| 1300002 | This window state is abnormal. | 1094| 1300003 | This window manager service works abnormally. | 1095 1096**Example** 1097 1098```ts 1099import { BusinessError } from '@ohos.base'; 1100 1101try { 1102 let promise = window.setGestureNavigationEnabled(true); 1103 promise.then(() => { 1104 console.info('Succeeded in setting gesture navigation enabled.'); 1105 }).catch((err: BusinessError) => { 1106 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err)); 1107 }); 1108} catch (exception) { 1109 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception)); 1110} 1111``` 1112 1113## window.setWaterMarkImage<sup>10+</sup> 1114setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean, callback: AsyncCallback<void>): void 1115 1116Sets the watermark image display status. This API uses an asynchronous callback to return the result. 1117 1118**System API**: This is a system API. 1119 1120**System capability**: SystemCapability.WindowManager.WindowManager.Core 1121 1122**Parameters** 1123 1124| Name | Type | Mandatory| Description | 1125| -------- | ------------------------- | ---- | -------------- | 1126| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Watermark image.| 1127| enable | boolean | Yes | Whether to display the watermark image. The value **true** means to display the watermark image, and **false** means the opposite.| 1128| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1129 1130**Error codes** 1131 1132For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1133 1134| ID| Error Message| 1135| ------- | --------------------------------------------- | 1136| 1300003 | This window manager service works abnormally. | 1137 1138**Example** 1139 1140```ts 1141import image from '@ohos.multimedia.image'; 1142import { BusinessError } from '@ohos.base'; 1143 1144let enable: boolean = true; 1145let color: ArrayBuffer = new ArrayBuffer(0); 1146let initializationOptions: image.InitializationOptions = { 1147 size: { 1148 height: 100, 1149 width: 100 1150 } 1151}; 1152image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { 1153 console.info('Succeeded in creating pixelmap.'); 1154 try { 1155 window.setWaterMarkImage(pixelMap, enable, (err: BusinessError) => { 1156 const errCode: number = err.code; 1157 if (errCode) { 1158 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(err)); 1159 return; 1160 } 1161 console.info('Succeeded in showing watermark image.'); 1162 }); 1163 } catch (exception) { 1164 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception)); 1165 } 1166}).catch((err: BusinessError) => { 1167 console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err)); 1168}); 1169``` 1170 1171## window.setWaterMarkImage<sup>10+</sup> 1172setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean): Promise<void> 1173 1174Sets the watermark image display status. This API uses a promise to return the result. 1175 1176**System API**: This is a system API. 1177 1178**System capability**: SystemCapability.WindowManager.WindowManager.Core 1179 1180**Parameters** 1181 1182| Name| Type | Mandatory | Description | 1183| ------ | --------------------------- | ---- | -------------------- | 1184| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| Watermark image.| 1185| enable | boolean | Yes | Whether to display the watermark image. The value **true** means to display the watermark image, and **false** means the opposite.| 1186 1187**Return value** 1188 1189| Type | Description | 1190| ------------------- | ------------------------- | 1191| Promise<void> | Promise that returns no value.| 1192 1193**Error codes** 1194 1195For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1196 1197| ID| Error Message| 1198| ------- | -------------------------------------------- | 1199| 1300003 | This window manager service works abnormally. | 1200 1201**Example** 1202 1203```ts 1204import image from '@ohos.multimedia.image'; 1205import { BusinessError } from '@ohos.base'; 1206 1207let enable: boolean = true; 1208let color: ArrayBuffer = new ArrayBuffer(0); 1209let initializationOptions: image.InitializationOptions = { 1210 size: { 1211 height: 100, 1212 width: 100 1213 } 1214}; 1215image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { 1216 console.info('Succeeded in creating pixelmap.'); 1217 try { 1218 let promise = window.setWaterMarkImage(pixelMap, enable); 1219 promise.then(() => { 1220 console.info('Succeeded in showing watermark image.'); 1221 }).catch((err: BusinessError) => { 1222 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(err)); 1223 }); 1224 } catch (exception) { 1225 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception)); 1226 } 1227}).catch((err: BusinessError) => { 1228 console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err)); 1229}); 1230``` 1231 1232## window.create<sup>(deprecated)</sup> 1233 1234create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 1235 1236Creates a subwindow. This API uses an asynchronous callback to return the result. 1237 1238> **NOTE** 1239> 1240> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead. 1241 1242**Model restriction**: This API can be used only in the FA model. 1243 1244**System capability**: SystemCapability.WindowManager.WindowManager.Core 1245 1246**Parameters** 1247 1248| Name | Type | Mandatory| Description | 1249| -------- | -------------------------------------- | ---- | ------------------------------------ | 1250| id | string | Yes | Window ID. | 1251| type | [WindowType](#windowtype7) | Yes | Window type. | 1252| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created.| 1253 1254**Example** 1255 1256```ts 1257import { BusinessError } from '@ohos.base'; 1258 1259let windowClass: window.Window | null = null; 1260window.create('first', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 1261 const errCode: number = err.code; 1262 if (errCode) { 1263 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 1264 return; 1265 } 1266 windowClass = data; 1267 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1268}); 1269``` 1270 1271## window.create<sup>(deprecated)</sup> 1272 1273create(id: string, type: WindowType): Promise<Window> 1274 1275Creates a subwindow. This API uses a promise to return the result. 1276 1277> **NOTE** 1278> 1279> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead. 1280 1281**Model restriction**: This API can be used only in the FA model. 1282 1283**System capability**: SystemCapability.WindowManager.WindowManager.Core 1284 1285**Parameters** 1286 1287| Name| Type | Mandatory| Description | 1288| ------ | ------------------------- | ---- | ---------- | 1289| id | string | Yes | Window ID. | 1290| type | [WindowType](#windowtype7) | Yes | Window type.| 1291 1292**Return value** 1293 1294| Type | Description | 1295| -------------------------------- | --------------------------------------- | 1296| Promise<[Window](#window)> | Promise used to return the subwindow created.| 1297 1298**Example** 1299 1300```ts 1301import { BusinessError } from '@ohos.base'; 1302 1303let windowClass: window.Window | null = null; 1304let promise = window.create('first', window.WindowType.TYPE_APP); 1305promise.then((data) => { 1306 windowClass = data; 1307 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1308}).catch((err: BusinessError) => { 1309 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 1310}); 1311``` 1312 1313## window.create<sup>(deprecated)</sup> 1314 1315create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 1316 1317Creates a system window. This API uses an asynchronous callback to return the result. 1318 1319> **NOTE** 1320> 1321> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9) instead. 1322 1323**System capability**: SystemCapability.WindowManager.WindowManager.Core 1324 1325**Parameters** 1326 1327| Name | Type | Mandatory| Description | 1328| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 1329| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current application context. | 1330| id | string | Yes | Window ID. | 1331| type | [WindowType](#windowtype7) | Yes | Window type. | 1332| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created.| 1333 1334**Example** 1335 1336```ts 1337import { BusinessError } from '@ohos.base'; 1338 1339let windowClass: window.Window | null = null; 1340window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 1341 const errCode: number = err.code; 1342 if (errCode) { 1343 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 1344 return; 1345 } 1346 windowClass = data; 1347 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 1348 windowClass.resetSize(500, 1000); 1349}); 1350``` 1351 1352## window.create<sup>(deprecated)</sup> 1353 1354create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 1355 1356Creates a system window. This API uses a promise to return the result. 1357 1358> **NOTE** 1359> 1360> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createWindow()](#windowcreatewindow9-1) instead. 1361 1362**System capability**: SystemCapability.WindowManager.WindowManager.Core 1363 1364**Parameters** 1365 1366| Name| Type | Mandatory| Description | 1367| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 1368| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current application context.| 1369| id | string | Yes | Window ID. | 1370| type | [WindowType](#windowtype7) | Yes | Window type. | 1371 1372**Return value** 1373 1374| Type | Description | 1375| -------------------------------- | --------------------------------------- | 1376| Promise<[Window](#window)> | Promise used to return the subwindow created.| 1377 1378**Example** 1379 1380```ts 1381import { BusinessError } from '@ohos.base'; 1382 1383let windowClass: window.Window | null = null; 1384let promise = window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT); 1385promise.then((data) => { 1386 windowClass = data; 1387 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 1388}).catch((err: BusinessError) => { 1389 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 1390}); 1391``` 1392 1393## window.find<sup>(deprecated)</sup> 1394 1395find(id: string, callback: AsyncCallback<Window>): void 1396 1397Finds a window based on the ID. This API uses an asynchronous callback to return the result. 1398 1399> **NOTE** 1400> 1401> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead. 1402 1403**System capability**: SystemCapability.WindowManager.WindowManager.Core 1404 1405**Parameters** 1406 1407| Name | Type | Mandatory| Description | 1408| -------- | -------------------------------------- | ---- | ------------------------------------ | 1409| id | string | Yes | Window ID. | 1410| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the window found.| 1411 1412**Example** 1413 1414```ts 1415import { BusinessError } from '@ohos.base'; 1416 1417let windowClass: window.Window | null = null; 1418window.find('alertWindow', (err: BusinessError, data) => { 1419 const errCode: number = err.code; 1420 if (errCode) { 1421 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 1422 return; 1423 } 1424 windowClass = data; 1425 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1426}); 1427``` 1428 1429## window.find<sup>(deprecated)</sup> 1430 1431find(id: string): Promise<Window> 1432 1433Finds a window based on the ID. This API uses a promise to return the result. 1434 1435> **NOTE** 1436> 1437> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [findWindow()](#windowfindwindow9) instead. 1438 1439**System capability**: SystemCapability.WindowManager.WindowManager.Core 1440 1441**Parameters** 1442 1443| Name| Type | Mandatory| Description | 1444| ------ | ------ | ---- | -------- | 1445| id | string | Yes | Window ID.| 1446 1447**Return value** 1448 1449| Type | Description | 1450| -------------------------------- | ------------------------------------- | 1451| Promise<[Window](#window)> | Promise used to return the window found.| 1452 1453**Example** 1454 1455```ts 1456import { BusinessError } from '@ohos.base'; 1457 1458let windowClass: window.Window | null = null; 1459let promise = window.find('alertWindow'); 1460promise.then((data) => { 1461 windowClass = data; 1462 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1463}).catch((err: BusinessError) => { 1464 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 1465}); 1466``` 1467 1468## window.getTopWindow<sup>(deprecated)</sup> 1469 1470getTopWindow(callback: AsyncCallback<Window>): void 1471 1472Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 1473 1474> **NOTE** 1475> 1476> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead. 1477 1478**Model restriction**: This API can be used only in the FA model. 1479 1480**System capability**: SystemCapability.WindowManager.WindowManager.Core 1481 1482**Parameters** 1483 1484| Name | Type | Mandatory| Description | 1485| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1486| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained.| 1487 1488**Example** 1489 1490```ts 1491import { BusinessError } from '@ohos.base'; 1492 1493let windowClass: window.Window | null = null; 1494window.getTopWindow((err: BusinessError, data) => { 1495 const errCode: number = err.code; 1496 if (errCode) { 1497 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1498 return; 1499 } 1500 windowClass = data; 1501 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1502}); 1503``` 1504 1505## window.getTopWindow<sup>(deprecated)</sup> 1506 1507getTopWindow(): Promise<Window> 1508 1509Obtains the top window of the current application. This API uses a promise to return the result. 1510 1511> **NOTE** 1512> 1513> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead. 1514 1515**Model restriction**: This API can be used only in the FA model. 1516 1517**System capability**: SystemCapability.WindowManager.WindowManager.Core 1518 1519**Return value** 1520 1521| Type | Description | 1522| -------------------------------- | ----------------------------------------------- | 1523| Promise<[Window](#window)> | Promise used to return the top window obtained.| 1524 1525**Example** 1526 1527```ts 1528import { BusinessError } from '@ohos.base'; 1529 1530let windowClass: window.Window | null = null; 1531let promise = window.getTopWindow(); 1532promise.then((data)=> { 1533 windowClass = data; 1534 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1535}).catch((err: BusinessError)=>{ 1536 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1537}); 1538``` 1539 1540## window.getTopWindow<sup>(deprecated)</sup> 1541 1542getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1543 1544Obtains the top window of the current application. This API uses an asynchronous callback to return the result. 1545 1546> **NOTE** 1547> 1548> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9) instead. 1549 1550**System capability**: SystemCapability.WindowManager.WindowManager.Core 1551 1552**Parameters** 1553 1554| Name | Type | Mandatory| Description | 1555| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1556| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current application context.| 1557| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained. | 1558 1559**Example** 1560 1561```ts 1562import { BusinessError } from '@ohos.base'; 1563 1564let windowClass: window.Window | null = null; 1565let promise = window.getTopWindow(); 1566promise.then((data) => { 1567 windowClass = data; 1568 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1569}).catch((err: BusinessError) => { 1570 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1571}); 1572``` 1573 1574## window.getTopWindow<sup>(deprecated)</sup> 1575 1576getTopWindow(ctx: BaseContext): Promise<Window> 1577 1578Obtains the top window of the current application. This API uses a promise to return the result. 1579 1580> **NOTE** 1581> 1582> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLastWindow()](#windowgetlastwindow9-1) instead. 1583 1584**System capability**: SystemCapability.WindowManager.WindowManager.Core 1585 1586**Parameters** 1587 1588| Name| Type | Mandatory| Description | 1589| ------ | ----------- | ---- | ------------------------------------------------------------ | 1590| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current application context.| 1591 1592**Return value** 1593 1594| Type | Description | 1595| -------------------------------- | ----------------------------------------------- | 1596| Promise<[Window](#window)> | Promise used to return the top window obtained.| 1597 1598**Example** 1599 1600```ts 1601import { BusinessError } from '@ohos.base'; 1602 1603let windowClass: window.Window | null = null; 1604let promise = window.getTopWindow(this.context); 1605promise.then((data) => { 1606 windowClass = data; 1607 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1608}).catch((err: BusinessError) => { 1609 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1610}); 1611``` 1612 1613## Window 1614 1615Represents the current window instance, which is the basic unit managed by the window manager. 1616 1617In the following API examples, you must use [getLastWindow()](#windowgetlastwindow9), [createWindow()](#windowcreatewindow9), or [findWindow()](#windowfindwindow9) to obtain a **Window** instance and then call a method in this instance. 1618 1619### hide<sup>7+</sup> 1620 1621hide (callback: AsyncCallback<void>): void 1622 1623Hides this window. This API uses an asynchronous callback to return the result. 1624 1625**System API**: This is a system API. 1626 1627**System capability**: SystemCapability.WindowManager.WindowManager.Core 1628 1629**Parameters** 1630 1631| Name | Type | Mandatory| Description | 1632| -------- | ------------------------- | ---- | ---------- | 1633| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1634 1635**Error codes** 1636 1637For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1638 1639| ID| Error Message| 1640| ------- | ------------------------------ | 1641| 1300002 | This window state is abnormal. | 1642 1643**Example** 1644 1645```ts 1646import { BusinessError } from '@ohos.base'; 1647 1648windowClass.hide((err: BusinessError) => { 1649 const errCode: number = err.code; 1650 if (errCode) { 1651 console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); 1652 return; 1653 } 1654 console.info('Succeeded in hiding the window.'); 1655}); 1656``` 1657 1658### hide<sup>7+</sup> 1659 1660hide(): Promise<void> 1661 1662Hides this window. This API uses a promise to return the result. 1663 1664**System API**: This is a system API. 1665 1666**System capability**: SystemCapability.WindowManager.WindowManager.Core 1667 1668**Return value** 1669 1670| Type | Description | 1671| ------------------- | ------------------------- | 1672| Promise<void> | Promise that returns no value.| 1673 1674**Error codes** 1675 1676For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1677 1678| ID| Error Message| 1679| ------- | ------------------------------ | 1680| 1300002 | This window state is abnormal. | 1681 1682**Example** 1683 1684```ts 1685import { BusinessError } from '@ohos.base'; 1686 1687let promise = windowClass.hide(); 1688promise.then(() => { 1689 console.info('Succeeded in hiding the window.'); 1690}).catch((err: BusinessError) => { 1691 console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); 1692}); 1693``` 1694 1695### hideWithAnimation<sup>9+</sup> 1696 1697hideWithAnimation(callback: AsyncCallback<void>): void 1698 1699Hides this window and plays an animation during the process. This API uses an asynchronous callback to return the result. 1700 1701**System API**: This is a system API. 1702 1703**System capability**: SystemCapability.WindowManager.WindowManager.Core 1704 1705**Parameters** 1706 1707| Name | Type | Mandatory| Description | 1708| -------- | ------------------------- | ---- | ---------- | 1709| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1710 1711**Error codes** 1712 1713For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1714 1715| ID| Error Message| 1716| ------- | -------------------------------------------- | 1717| 1300002 | This window state is abnormal. | 1718| 1300003 | This window manager service works abnormally. | 1719| 1300004 | Unauthorized operation. | 1720 1721**Example** 1722 1723```ts 1724import { BusinessError } from '@ohos.base'; 1725 1726windowClass.hideWithAnimation((err: BusinessError) => { 1727 const errCode: number = err.code; 1728 if (errCode) { 1729 console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 1730 return; 1731 } 1732 console.info('Succeeded in hiding the window with animation.'); 1733}); 1734``` 1735 1736### hideWithAnimation<sup>9+</sup> 1737 1738hideWithAnimation(): Promise<void> 1739 1740Hides this window and plays an animation during the process. This API uses a promise to return the result. 1741 1742**System API**: This is a system API. 1743 1744**System capability**: SystemCapability.WindowManager.WindowManager.Core 1745 1746**Return value** 1747 1748| Type | Description | 1749| ------------------- | ------------------------- | 1750| Promise<void> | Promise that returns no value.| 1751 1752**Error codes** 1753 1754For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1755 1756| ID| Error Message| 1757| ------- | -------------------------------------------- | 1758| 1300002 | This window state is abnormal. | 1759| 1300003 | This window manager service works abnormally. | 1760| 1300004 | Unauthorized operation. | 1761 1762**Example** 1763 1764```ts 1765import { BusinessError } from '@ohos.base'; 1766 1767let promise = windowClass.hideWithAnimation(); 1768promise.then(() => { 1769 console.info('Succeeded in hiding the window with animation.'); 1770}).catch((err: BusinessError) => { 1771 console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 1772}); 1773``` 1774 1775### showWindow<sup>9+</sup> 1776 1777showWindow(callback: AsyncCallback<void>): void 1778 1779Shows this window. This API uses an asynchronous callback to return the result. 1780 1781**System capability**: SystemCapability.WindowManager.WindowManager.Core 1782 1783**Parameters** 1784 1785| Name| Type| Mandatory| Description| 1786| -------- | ------------------------- | -- | --------- | 1787| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1788 1789**Error codes** 1790 1791For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1792 1793| ID| Error Message| 1794| ------- | ------------------------------ | 1795| 1300002 | This window state is abnormal. | 1796 1797**Example** 1798 1799```ts 1800import { BusinessError } from '@ohos.base'; 1801 1802windowClass.showWindow((err: BusinessError) => { 1803 const errCode: number = err.code; 1804 if (errCode) { 1805 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1806 return; 1807 } 1808 console.info('Succeeded in showing the window.'); 1809}); 1810``` 1811 1812### showWindow<sup>9+</sup> 1813 1814showWindow(): Promise<void> 1815 1816Shows this window. This API uses a promise to return the result. 1817 1818**System capability**: SystemCapability.WindowManager.WindowManager.Core 1819 1820**Return value** 1821 1822| Type| Description| 1823| ------------------- | ----------------------- | 1824| Promise<void> | Promise that returns no value.| 1825 1826**Error codes** 1827 1828For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1829 1830| ID| Error Message| 1831| ------- | ------------------------------ | 1832| 1300002 | This window state is abnormal. | 1833 1834**Example** 1835 1836```ts 1837import { BusinessError } from '@ohos.base'; 1838 1839let promise = windowClass.showWindow(); 1840promise.then(() => { 1841 console.info('Succeeded in showing the window.'); 1842}).catch((err: BusinessError) => { 1843 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1844}); 1845``` 1846 1847### showWithAnimation<sup>9+</sup> 1848 1849showWithAnimation(callback: AsyncCallback<void>): void 1850 1851Shows this window and plays an animation during the process. This API uses an asynchronous callback to return the result. 1852 1853**System API**: This is a system API. 1854 1855**System capability**: SystemCapability.WindowManager.WindowManager.Core 1856 1857**Parameters** 1858 1859| Name | Type | Mandatory| Description | 1860| -------- | ------------------------- | ---- | ---------- | 1861| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1862 1863**Error codes** 1864 1865For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1866 1867| ID| Error Message| 1868| ------- | -------------------------------------------- | 1869| 1300002 | This window state is abnormal. | 1870| 1300003 | This window manager service works abnormally. | 1871| 1300004 | Unauthorized operation. | 1872 1873**Example** 1874 1875```ts 1876import { BusinessError } from '@ohos.base'; 1877 1878windowClass.showWithAnimation((err: BusinessError) => { 1879 const errCode: number = err.code; 1880 if (errCode) { 1881 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 1882 return; 1883 } 1884 console.info('Succeeded in showing the window with animation.'); 1885}); 1886``` 1887 1888### showWithAnimation<sup>9+</sup> 1889 1890showWithAnimation(): Promise<void> 1891 1892Shows this window and plays an animation during the process. This API uses a promise to return the result. 1893 1894**System API**: This is a system API. 1895 1896**System capability**: SystemCapability.WindowManager.WindowManager.Core 1897 1898**Return value** 1899 1900| Type | Description | 1901| ------------------- | ------------------------- | 1902| Promise<void> | Promise that returns no value.| 1903 1904**Error codes** 1905 1906For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1907 1908| ID| Error Message| 1909| ------- | -------------------------------------------- | 1910| 1300002 | This window state is abnormal. | 1911| 1300003 | This window manager service works abnormally. | 1912| 1300004 | Unauthorized operation. | 1913 1914**Example** 1915 1916```ts 1917import { BusinessError } from '@ohos.base'; 1918 1919let promise = windowClass.showWithAnimation(); 1920promise.then(() => { 1921 console.info('Succeeded in showing the window with animation.'); 1922}).catch((err: BusinessError) => { 1923 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 1924}); 1925``` 1926 1927### destroyWindow<sup>9+</sup> 1928 1929destroyWindow(callback: AsyncCallback<void>): void 1930 1931Destroys this window. This API uses an asynchronous callback to return the result. 1932 1933**System capability**: SystemCapability.WindowManager.WindowManager.Core 1934 1935**Parameters** 1936 1937| Name| Type| Mandatory| Description| 1938| -------- | ------------------------- | -- | --------- | 1939| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1940 1941**Error codes** 1942 1943For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1944 1945| ID| Error Message| 1946| ------- | -------------------------------------------- | 1947| 1300002 | This window state is abnormal. | 1948| 1300003 | This window manager service works abnormally. | 1949 1950**Example** 1951 1952```ts 1953import { BusinessError } from '@ohos.base'; 1954 1955windowClass.destroyWindow((err) => { 1956 const errCode: number = err.code; 1957 if (errCode) { 1958 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 1959 return; 1960 } 1961 console.info('Succeeded in destroying the window.'); 1962}); 1963``` 1964 1965### destroyWindow<sup>9+</sup> 1966 1967destroyWindow(): Promise<void> 1968 1969Destroys this window. This API uses a promise to return the result. 1970 1971**System capability**: SystemCapability.WindowManager.WindowManager.Core 1972 1973**Return value** 1974 1975| Type| Description| 1976| ------------------- | ------------------------ | 1977| Promise<void> | Promise that returns no value.| 1978 1979**Error codes** 1980 1981For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 1982 1983| ID| Error Message| 1984| ------- | -------------------------------------------- | 1985| 1300002 | This window state is abnormal. | 1986| 1300003 | This window manager service works abnormally. | 1987 1988**Example** 1989 1990```ts 1991import { BusinessError } from '@ohos.base'; 1992 1993let promise = windowClass.destroyWindow(); 1994promise.then(() => { 1995 console.info('Succeeded in destroying the window.'); 1996}).catch((err: BusinessError) => { 1997 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 1998}); 1999``` 2000 2001### moveWindowTo<sup>9+</sup> 2002 2003moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 2004 2005Moves this window. This API uses an asynchronous callback to return the result. 2006 2007This operation is not supported in a window in full-screen mode. 2008 2009**System capability**: SystemCapability.WindowManager.WindowManager.Core 2010 2011**Parameters** 2012 2013| Name| Type| Mandatory| Description| 2014| -------- | ------------------------- | -- | --------------------------------------------- | 2015| 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. The value must be an integer.| 2016| y | number | Yes| Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards. The value must be an integer.| 2017| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 2018 2019**Error codes** 2020 2021For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2022 2023| ID| Error Message| 2024| ------- | -------------------------------------------- | 2025| 1300002 | This window state is abnormal. | 2026| 1300003 | This window manager service works abnormally. | 2027 2028**Example** 2029 2030```ts 2031import { BusinessError } from '@ohos.base'; 2032 2033try { 2034 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 2035 const errCode: number = err.code; 2036 if (errCode) { 2037 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 2038 return; 2039 } 2040 console.info('Succeeded in moving the window.'); 2041 }); 2042} catch (exception) { 2043 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 2044} 2045``` 2046 2047### moveWindowTo<sup>9+</sup> 2048 2049moveWindowTo(x: number, y: number): Promise<void> 2050 2051Moves this window. This API uses a promise to return the result. 2052 2053This operation is not supported in a window in full-screen mode. 2054 2055**System capability**: SystemCapability.WindowManager.WindowManager.Core 2056 2057**Parameters** 2058 2059| Name| Type| Mandatory| Description| 2060| -- | ----- | -- | --------------------------------------------- | 2061| 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. The value must be an integer.| 2062| y | number | Yes| Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards. The value must be an integer.| 2063 2064**Return value** 2065 2066| Type| Description| 2067| ------------------- | ------------------------ | 2068| Promise<void> | Promise that returns no value.| 2069 2070**Error codes** 2071 2072For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2073 2074| ID| Error Message| 2075| ------- | -------------------------------------------- | 2076| 1300002 | This window state is abnormal. | 2077| 1300003 | This window manager service works abnormally. | 2078 2079**Example** 2080 2081```ts 2082import { BusinessError } from '@ohos.base'; 2083 2084try { 2085 let promise = windowClass.moveWindowTo(300, 300); 2086 promise.then(() => { 2087 console.info('Succeeded in moving the window.'); 2088 }).catch((err: BusinessError) => { 2089 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 2090 }); 2091} catch (exception) { 2092 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 2093} 2094``` 2095 2096### resize<sup>9+</sup> 2097 2098resize(width: number, height: number, callback: AsyncCallback<void>): void 2099 2100Changes the size of this window. This API uses an asynchronous callback to return the result. 2101 2102The main window and subwindow have the following size limits: [320, 2560] in width and [240, 2560] in height, both in units of vp. 2103 2104The system window has the following size limits: [0, 2560] in width and [0, 2560] in height, both in units of vp. 2105 2106The new width and height you set must meet the limits. 2107 2108This operation is not supported in a window in full-screen mode. 2109 2110**System capability**: SystemCapability.WindowManager.WindowManager.Core 2111 2112**Parameters** 2113 2114| Name| Type| Mandatory| Description| 2115| -------- | ------------------------- | -- | ------------------------ | 2116| width | number | Yes| New width of the window, in px. The value must be an integer.| 2117| height | number | Yes| New height of the window, in px. The value must be an integer.| 2118| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 2119 2120**Error codes** 2121 2122For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2123 2124| ID| Error Message| 2125| ------- | -------------------------------------------- | 2126| 1300002 | This window state is abnormal. | 2127| 1300003 | This window manager service works abnormally. | 2128 2129**Example** 2130 2131```ts 2132import { BusinessError } from '@ohos.base'; 2133 2134try { 2135 windowClass.resize(500, 1000, (err: BusinessError) => { 2136 const errCode: number = err.code; 2137 if (errCode) { 2138 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 2139 return; 2140 } 2141 console.info('Succeeded in changing the window size.'); 2142 }); 2143} catch (exception) { 2144 console.error('Failed to change the window size. Cause:' + JSON.stringify(exception)); 2145} 2146``` 2147 2148### resize<sup>9+</sup> 2149 2150resize(width: number, height: number): Promise<void> 2151 2152Changes the size of this window. This API uses a promise to return the result. 2153 2154The main window and subwindow have the following size limits: [320, 2560] in width and [240, 2560] in height, both in units of vp. 2155 2156The system window has the following size limits: [0, 2560] in width and [0, 2560] in height, both in units of vp. 2157 2158The new width and height you set must meet the limits. 2159 2160This operation is not supported in a window in full-screen mode. 2161 2162**System capability**: SystemCapability.WindowManager.WindowManager.Core 2163 2164**Parameters** 2165 2166| Name| Type| Mandatory| Description| 2167| ------ | ------ | -- | ------------------------ | 2168| width | number | Yes| New width of the window, in px. The value must be an integer.| 2169| height | number | Yes| New height of the window, in px. The value must be an integer.| 2170 2171**Return value** 2172 2173| Type| Description| 2174| ------------------- | ------------------------ | 2175| Promise<void> | Promise that returns no value.| 2176 2177**Error codes** 2178 2179For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2180 2181| ID| Error Message| 2182| ------- | -------------------------------------------- | 2183| 1300002 | This window state is abnormal. | 2184| 1300003 | This window manager service works abnormally. | 2185 2186**Example** 2187 2188```ts 2189import { BusinessError } from '@ohos.base'; 2190 2191try { 2192 let promise = windowClass.resize(500, 1000); 2193 promise.then(() => { 2194 console.info('Succeeded in changing the window size.'); 2195 }).catch((err: BusinessError) => { 2196 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 2197 }); 2198} catch (exception) { 2199 console.error('Failed to change the window size. Cause: ' + JSON.stringify(exception)); 2200} 2201``` 2202 2203### setWindowMode<sup>9+</sup> 2204 2205setWindowMode(mode: WindowMode, callback: AsyncCallback<void>): void 2206 2207Sets the mode of this window. This API uses an asynchronous callback to return the result. 2208 2209**System API**: This is a system API. 2210 2211**System capability**: SystemCapability.WindowManager.WindowManager.Core 2212 2213**Parameters** 2214 2215| Name| Type| Mandatory| Description| 2216| -------- | -------------------------- | -- | --------- | 2217| mode | [WindowMode](#windowmode7) | Yes| Window mode to set.| 2218| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2219 2220**Error codes** 2221 2222For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2223 2224| ID| Error Message| 2225| ------- | -------------------------------------------- | 2226| 1300002 | This window state is abnormal. | 2227| 1300003 | This window manager service works abnormally. | 2228 2229**Example** 2230 2231```ts 2232import { BusinessError } from '@ohos.base'; 2233 2234let mode = window.WindowMode.FULLSCREEN; 2235try { 2236 windowClass.setWindowMode(mode, (err: BusinessError) => { 2237 const errCode: number = err.code; 2238 if (errCode) { 2239 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err)); 2240 return; 2241 } 2242 console.info('Succeeded in setting the window mode.'); 2243 }); 2244} catch (exception) { 2245 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception)); 2246} 2247``` 2248 2249### setWindowMode<sup>9+</sup> 2250 2251setWindowMode(mode: WindowMode): Promise<void> 2252 2253Sets the type of this window. This API uses a promise to return the result. 2254 2255**System API**: This is a system API. 2256 2257**System capability**: SystemCapability.WindowManager.WindowManager.Core 2258 2259**Parameters** 2260 2261| Name| Type| Mandatory| Description| 2262| -------- | -------------------------- | -- | --------- | 2263| mode | [WindowMode](#windowmode7) | Yes| Window mode to set.| 2264 2265**Return value** 2266 2267| Type| Description| 2268| ------------------- | ----------------------- | 2269| Promise<void> | Promise that returns no value.| 2270 2271**Error codes** 2272 2273For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2274 2275| ID| Error Message| 2276| ------- | -------------------------------------------- | 2277| 1300002 | This window state is abnormal. | 2278| 1300003 | This window manager service works abnormally. | 2279 2280**Example** 2281 2282```ts 2283import { BusinessError } from '@ohos.base'; 2284 2285let mode = window.WindowMode.FULLSCREEN; 2286try { 2287 let promise = windowClass.setWindowMode(mode); 2288 promise.then(() => { 2289 console.info('Succeeded in setting the window mode.'); 2290 }).catch((err: BusinessError) => { 2291 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err)); 2292 }); 2293} catch (exception) { 2294 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception)); 2295} 2296``` 2297 2298### getWindowProperties<sup>9+</sup> 2299 2300getWindowProperties(): WindowProperties 2301 2302Obtains the properties of this window. 2303 2304**System capability**: SystemCapability.WindowManager.WindowManager.Core 2305 2306**Return value** 2307 2308| Type| Description| 2309| ------------------------------------- | ------------- | 2310| [WindowProperties](#windowproperties) | Window properties obtained.| 2311 2312**Error codes** 2313 2314For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2315 2316| ID| Error Message| 2317| ------- | ------------------------------ | 2318| 1300002 | This window state is abnormal. | 2319 2320**Example** 2321 2322```ts 2323try { 2324 let properties = windowClass.getWindowProperties(); 2325} catch (exception) { 2326 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); 2327} 2328``` 2329 2330### getWindowAvoidArea<sup>9+</sup> 2331 2332getWindowAvoidArea(type: AvoidAreaType): AvoidArea 2333 2334Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. 2335 2336**System capability**: SystemCapability.WindowManager.WindowManager.Core 2337 2338**Parameters** 2339 2340| Name| Type| Mandatory| Description| 2341| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2342| type | [AvoidAreaType](#avoidareatype7) | Yes| Type of the area.| 2343 2344**Return value** 2345 2346| Type| Description| 2347|--------------------------| ----------------- | 2348| [AvoidArea](#avoidarea7) | Area where the window cannot be displayed.| 2349 2350**Error codes** 2351 2352For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2353 2354| ID| Error Message| 2355| ------- | ------------------------------ | 2356| 1300002 | This window state is abnormal. | 2357 2358**Example** 2359 2360```ts 2361let type = window.AvoidAreaType.TYPE_SYSTEM; 2362try { 2363 let avoidArea = windowClass.getWindowAvoidArea(type); 2364} catch (exception) { 2365 console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception)); 2366} 2367``` 2368 2369### setWindowLayoutFullScreen<sup>9+</sup> 2370 2371setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 2372 2373Sets whether the window layout is immersive. This API uses an asynchronous callback to return the result. 2374 2375An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 2376 2377A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 2378 2379**System capability**: SystemCapability.WindowManager.WindowManager.Core 2380 2381**Parameters** 2382 2383| Name| Type| Mandatory| Description| 2384| ------------------ | ------------------------- | -- | --------- | 2385| isLayoutFullScreen | boolean | Yes| Whether the window layout is immersive. (The status bar and navigation bar of the immersive layout are still displayed.) The value **true** means that the window layout is immersive, and **false** means the opposite.| 2386| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2387 2388**Error codes** 2389 2390For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2391 2392| ID| Error Message| 2393| ------- | -------------------------------------------- | 2394| 1300002 | This window state is abnormal. | 2395| 1300003 | This window manager service works abnormally. | 2396 2397**Example** 2398 2399```ts 2400import { BusinessError } from '@ohos.base'; 2401 2402let isLayoutFullScreen = true; 2403try { 2404 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 2405 const errCode: number = err.code; 2406 if (errCode) { 2407 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 2408 return; 2409 } 2410 console.info('Succeeded in setting the window layout to full-screen mode.'); 2411 }); 2412} catch (exception) { 2413 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 2414} 2415``` 2416 2417### setWindowLayoutFullScreen<sup>9+</sup> 2418 2419setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 2420 2421Sets whether the window layout is immersive. This API uses a promise to return the result. 2422 2423An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 2424 2425A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 2426 2427**System capability**: SystemCapability.WindowManager.WindowManager.Core 2428 2429**Parameters** 2430 2431| Name| Type| Mandatory| Description| 2432| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 2433| isLayoutFullScreen | boolean | Yes| Whether the window layout is immersive. (The status bar and navigation bar of the immersive layout are still displayed.) The value **true** means that the window layout is immersive, and **false** means the opposite.| 2434 2435**Return value** 2436 2437| Type| Description| 2438| ------------------- | ------------------------ | 2439| Promise<void> | Promise that returns no value.| 2440 2441**Error codes** 2442 2443For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2444 2445| ID| Error Message| 2446| ------- | -------------------------------------------- | 2447| 1300002 | This window state is abnormal. | 2448| 1300003 | This window manager service works abnormally. | 2449 2450**Example** 2451 2452```ts 2453import { BusinessError } from '@ohos.base'; 2454 2455let isLayoutFullScreen = true; 2456try { 2457 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 2458 promise.then(() => { 2459 console.info('Succeeded in setting the window layout to full-screen mode.'); 2460 }).catch((err: BusinessError) => { 2461 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 2462 }); 2463} catch (exception) { 2464 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 2465} 2466``` 2467 2468### setWindowSystemBarEnable<sup>9+</sup> 2469 2470setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 2471 2472Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 2473 2474**System capability**: SystemCapability.WindowManager.WindowManager.Core 2475 2476**Parameters** 2477 2478| Name| Type| Mandatory| Description| 2479| -------- | ---------------------------- | -- | --------- | 2480| names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 2481| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2482 2483**Error codes** 2484 2485For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2486 2487| ID| Error Message| 2488| ------- | -------------------------------------------- | 2489| 1300002 | This window state is abnormal. | 2490| 1300003 | This window manager service works abnormally. | 2491 2492**Example** 2493 2494```ts 2495// In this example, the status bar and navigation bar are not displayed. 2496import { BusinessError } from '@ohos.base'; 2497 2498let names: Array<'status' | 'navigation'> = []; 2499try { 2500 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 2501 const errCode: number = err.code; 2502 if (errCode) { 2503 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 2504 return; 2505 } 2506 console.info('Succeeded in setting the system bar to be invisible.'); 2507 }); 2508} catch (exception) { 2509 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 2510} 2511``` 2512 2513### setWindowSystemBarEnable<sup>9+</sup> 2514 2515setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2516 2517Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 2518 2519**System capability**: SystemCapability.WindowManager.WindowManager.Core 2520 2521**Parameters** 2522 2523| Name| Type | Mandatory| Description| 2524| ----- | ---------------------------- | -- | --------------------------------- | 2525| names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.| 2526 2527**Return value** 2528 2529| Type| Description| 2530| ------------------- | ------------------------ | 2531| Promise<void> | Promise that returns no value.| 2532 2533**Error codes** 2534 2535For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2536 2537| ID| Error Message| 2538| ------- | -------------------------------------------- | 2539| 1300002 | This window state is abnormal. | 2540| 1300003 | This window manager service works abnormally. | 2541 2542**Example** 2543 2544```ts 2545// In this example, the status bar and navigation bar are not displayed. 2546import { BusinessError } from '@ohos.base'; 2547 2548let names: Array<'status' | 'navigation'> = []; 2549try { 2550 let promise = windowClass.setWindowSystemBarEnable(names); 2551 promise.then(() => { 2552 console.info('Succeeded in setting the system bar to be invisible.'); 2553 }).catch((err: BusinessError) => { 2554 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 2555 }); 2556} catch (exception) { 2557 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 2558} 2559``` 2560 2561### setWindowSystemBarProperties<sup>9+</sup> 2562 2563setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 2564 2565Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 2566 2567**System capability**: SystemCapability.WindowManager.WindowManager.Core 2568 2569**Parameters** 2570 2571| Name | Type | Mandatory| Description | 2572| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2573| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| 2574| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2575 2576**Error codes** 2577 2578For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2579 2580| ID| Error Message| 2581| ------- | -------------------------------------------- | 2582| 1300002 | This window state is abnormal. | 2583| 1300003 | This window manager service works abnormally. | 2584 2585**Example** 2586 2587```ts 2588import { BusinessError } from '@ohos.base'; 2589 2590let SystemBarProperties: window.SystemBarProperties = { 2591 statusBarColor: '#ff00ff', 2592 navigationBarColor: '#00ff00', 2593 // The following properties are supported since API version 8. 2594 statusBarContentColor: '#ffffff', 2595 navigationBarContentColor: '#00ffff' 2596}; 2597try { 2598 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 2599 const errCode: number = err.code; 2600 if (errCode) { 2601 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 2602 return; 2603 } 2604 console.info('Succeeded in setting the system bar properties.'); 2605 }); 2606} catch (exception) { 2607 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 2608} 2609``` 2610 2611### setWindowSystemBarProperties<sup>9+</sup> 2612 2613setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2614 2615Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 2616 2617**System capability**: SystemCapability.WindowManager.WindowManager.Core 2618 2619**Parameters** 2620 2621| Name | Type | Mandatory| Description | 2622| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2623| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar.| 2624 2625**Return value** 2626 2627| Type | Description | 2628| ------------------- | ------------------------- | 2629| Promise<void> | Promise that returns no value.| 2630 2631**Error codes** 2632 2633For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2634 2635| ID| Error Message| 2636| ------- | -------------------------------------------- | 2637| 1300002 | This window state is abnormal. | 2638| 1300003 | This window manager service works abnormally. | 2639 2640**Example** 2641 2642```ts 2643import { BusinessError } from '@ohos.base'; 2644 2645let SystemBarProperties: window.SystemBarProperties = { 2646 statusBarColor: '#ff00ff', 2647 navigationBarColor: '#00ff00', 2648 // The following properties are supported since API version 8. 2649 statusBarContentColor: '#ffffff', 2650 navigationBarContentColor: '#00ffff' 2651}; 2652try { 2653 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2654 promise.then(() => { 2655 console.info('Succeeded in setting the system bar properties.'); 2656 }).catch((err: BusinessError) => { 2657 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 2658 }); 2659} catch (exception) { 2660 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 2661} 2662``` 2663 2664### setPreferredOrientation<sup>9+</sup> 2665 2666setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2667 2668Sets the preferred orientation for this window. This API uses an asynchronous callback to return the result. 2669 2670**System capability**: SystemCapability.WindowManager.WindowManager.Core 2671 2672**Parameters** 2673 2674| Name | Type | Mandatory| Description | 2675| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2676| Orientation | [Orientation](#orientation9) | Yes | Orientation to set. | 2677| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2678 2679**Error codes** 2680 2681For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2682 2683| ID| Error Message| 2684| ------- | ------------------------------ | 2685| 1300002 | This window state is abnormal. | 2686 2687**Example** 2688 2689```ts 2690import { BusinessError } from '@ohos.base'; 2691 2692let orientation = window.Orientation.AUTO_ROTATION; 2693try { 2694 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 2695 const errCode: number = err.code; 2696 if (errCode) { 2697 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); 2698 return; 2699 } 2700 console.info('Succeeded in setting window orientation.'); 2701 }); 2702} catch (exception) { 2703 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 2704} 2705``` 2706 2707### setPreferredOrientation<sup>9+</sup> 2708 2709setPreferredOrientation(orientation: Orientation): Promise<void> 2710 2711Sets the preferred orientation for this window. This API uses a promise to return the result. 2712 2713**System capability**: SystemCapability.WindowManager.WindowManager.Core 2714 2715**Parameters** 2716 2717| Name | Type | Mandatory| Description | 2718| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2719| Orientation | [Orientation](#orientation9) | Yes | Orientation to set. | 2720 2721**Return value** 2722 2723| Type | Description | 2724| ------------------- | ------------------------- | 2725| Promise<void> | Promise that returns no value.| 2726 2727**Error codes** 2728 2729For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2730 2731| ID| Error Message| 2732| ------- | ------------------------------ | 2733| 1300002 | This window state is abnormal. | 2734 2735**Example** 2736 2737```ts 2738import { BusinessError } from '@ohos.base'; 2739 2740let orientation = window.Orientation.AUTO_ROTATION; 2741try { 2742 let promise = windowClass.setPreferredOrientation(orientation); 2743 promise.then(() => { 2744 console.info('Succeeded in setting the window orientation.'); 2745 }).catch((err: BusinessError) => { 2746 console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err)); 2747 }); 2748} catch (exception) { 2749 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 2750} 2751``` 2752 2753### getUIContext<sup>10+</sup> 2754 2755getUIContext(): UIContext 2756 2757Obtain a **UIContext** instance. 2758 2759**Model restriction**: This API can be used only in the stage model. 2760 2761**System capability**: SystemCapability.WindowManager.WindowManager.Core 2762 2763**Return value** 2764 2765| Type | Description | 2766| ---------- | ---------------------- | 2767| [UIContext](./js-apis-arkui-UIContext.md#uicontext) | **UIContext** instance obtained.| 2768 2769**Error codes** 2770 2771For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2772 2773| ID| Error Message| 2774| ------- | ------------------------------ | 2775| 1300002 | This window state is abnormal. | 2776 2777**Example** 2778 2779```ts 2780import UIAbility from '@ohos.app.ability.UIAbility'; 2781import window from '@ohos.window'; 2782import { BusinessError } from '@ohos.base'; 2783import { UIContext } from '@ohos.arkui.UIContext'; 2784 2785export default class EntryAbility extends UIAbility { 2786 onWindowStageCreate(windowStage: window.WindowStage) { 2787 // Load content for the main window. 2788 windowStage.loadContent("pages/page2", (err: BusinessError) => { 2789 let errCode: number = err.code; 2790 if (errCode) { 2791 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2792 return; 2793 } 2794 console.info('Succeeded in loading the content.'); 2795 // Obtain the main window. 2796 let windowClass: window.Window | null = null; 2797 windowStage.getMainWindow((err: BusinessError, data) => { 2798 let errCode: number = err.code; 2799 if (errCode) { 2800 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 2801 return; 2802 } 2803 windowClass = data; 2804 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2805 // Obtain a UIContext instance. 2806 let uiContext: UIContext | null = null; 2807 uiContext = windowClass.getUIContext(); 2808 }) 2809 }); 2810 } 2811}; 2812``` 2813 2814### setUIContent<sup>9+</sup> 2815 2816setUIContent(path: string, callback: AsyncCallback<void>): void 2817 2818Loads content from a page to this window. This API uses an asynchronous callback to return the result. 2819 2820**System capability**: SystemCapability.WindowManager.WindowManager.Core 2821 2822**Parameters** 2823 2824| Name| Type| Mandatory| Description| 2825| -------- | ------------------------- | -- | -------------------- | 2826| path | string | Yes| Path of the page from which the content will be loaded.| 2827| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 2828 2829**Error codes** 2830 2831For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2832 2833| ID| Error Message| 2834| ------- | -------------------------------------------- | 2835| 1300002 | This window state is abnormal. | 2836| 1300003 | This window manager service works abnormally. | 2837 2838**Example** 2839 2840```ts 2841import { BusinessError } from '@ohos.base'; 2842 2843try { 2844 windowClass.setUIContent('pages/page2/page2', (err: BusinessError) => { 2845 const errCode: number = err.code; 2846 if (errCode) { 2847 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2848 return; 2849 } 2850 console.info('Succeeded in loading the content.'); 2851 }); 2852} catch (exception) { 2853 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2854} 2855``` 2856 2857### setUIContent<sup>9+</sup> 2858 2859setUIContent(path: string): Promise<void> 2860 2861Loads content from a page to this window. This API uses a promise to return the result. 2862 2863**System capability**: SystemCapability.WindowManager.WindowManager.Core 2864 2865**Parameters** 2866 2867| Name| Type| Mandatory| Description| 2868| ---- | ------ | -- | ------------------ | 2869| path | string | Yes| Path of the page from which the content will be loaded.| 2870 2871**Return value** 2872 2873| Type| Description| 2874| ------------------- | ------------------------ | 2875| Promise<void> | Promise that returns no value.| 2876 2877**Error codes** 2878 2879For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2880 2881| ID| Error Message| 2882| ------- | -------------------------------------------- | 2883| 1300002 | This window state is abnormal. | 2884| 1300003 | This window manager service works abnormally. | 2885 2886**Example** 2887 2888```ts 2889import { BusinessError } from '@ohos.base'; 2890 2891try { 2892 let promise = windowClass.setUIContent('pages/page2/page2'); 2893 promise.then(() => { 2894 console.info('Succeeded in loading the content.'); 2895 }).catch((err: BusinessError) => { 2896 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 2897 }); 2898} catch (exception) { 2899 console.error('Failed to load the content. Cause: ' + JSON.stringify(exception)); 2900} 2901``` 2902 2903### loadContent<sup>9+</sup> 2904 2905loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2906 2907Loads content from a page associated with a local storage to this window. This API uses an asynchronous callback to return the result. 2908 2909**Model restriction**: This API can be used only in the stage model. 2910 2911**System capability**: SystemCapability.WindowManager.WindowManager.Core 2912 2913**Parameters** 2914 2915| Name | Type | Mandatory| Description | 2916| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2917| path | string | Yes | Path of the page from which the content will be loaded. | 2918| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | A storage unit, which provides storage for variable state properties and non-variable state properties of an application.| 2919| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2920 2921**Error codes** 2922 2923For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2924 2925| ID| Error Message| 2926| ------- | -------------------------------------------- | 2927| 1300002 | This window state is abnormal. | 2928| 1300003 | This window manager service works abnormally. | 2929 2930**Example** 2931 2932```ts 2933import UIAbility from '@ohos.app.ability.UIAbility'; 2934import window from '@ohos.window'; 2935import { BusinessError } from '@ohos.base'; 2936 2937export default class EntryAbility extends UIAbility { 2938 // ... 2939 2940 onWindowStageCreate(windowStage: window.WindowStage) { 2941 console.log('onWindowStageCreate'); 2942 let windowClass: window.Window | null = null; 2943 let storage: LocalStorage = new LocalStorage(); 2944 storage.setOrCreate('storageSimpleProp', 121); 2945 try { 2946 if (!windowClass) { 2947 console.info('Failed to load the content. Cause: windowClass is null'); 2948 } 2949 else { 2950 (windowClass as window.Window).loadContent('pages/page2', storage, (err: BusinessError) => { 2951 const errCode: number = err.code; 2952 if (errCode) { 2953 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2954 return; 2955 } 2956 console.info('Succeeded in loading the content.'); 2957 }); 2958 } 2959 } catch (exception) { 2960 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2961 } 2962 } 2963}; 2964``` 2965 2966### loadContent<sup>9+</sup> 2967 2968loadContent(path: string, storage: LocalStorage): Promise<void> 2969 2970Loads content from a page associated with a local storage to this window. This API uses a promise to return the result. 2971 2972**Model restriction**: This API can be used only in the stage model. 2973 2974**System capability**: SystemCapability.WindowManager.WindowManager.Core 2975 2976**Parameters** 2977 2978| Name | Type | Mandatory| Description | 2979| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2980| path | string | Yes | Path of the page from which the content will be loaded. | 2981| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | A storage unit, which provides storage for variable state properties and non-variable state properties of an application.| 2982 2983**Return value** 2984 2985| Type | Description | 2986| ------------------- | ------------------------- | 2987| Promise<void> | Promise that returns no value.| 2988 2989**Error codes** 2990 2991For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 2992 2993| ID| Error Message| 2994| ------- | -------------------------------------------- | 2995| 1300002 | This window state is abnormal. | 2996| 1300003 | This window manager service works abnormally. | 2997 2998**Example** 2999 3000```ts 3001import UIAbility from '@ohos.app.ability.UIAbility'; 3002import window from '@ohos.window'; 3003import { BusinessError } from '@ohos.base'; 3004 3005export default class EntryAbility extends UIAbility { 3006 // ... 3007 3008 onWindowStageCreate(windowStage: window.WindowStage) { 3009 console.log('onWindowStageCreate'); 3010 let windowClass: window.Window | null = null; 3011 let storage: LocalStorage = new LocalStorage(); 3012 storage.setOrCreate('storageSimpleProp', 121); 3013 try { 3014 if (!windowClass) { 3015 console.info('Failed to load the content. Cause: windowClass is null'); 3016 } 3017 else { 3018 let promise = (windowClass as window.Window).loadContent('pages/page2', storage); 3019 promise.then(() => { 3020 console.info('Succeeded in loading the content.'); 3021 }).catch((err: BusinessError) => { 3022 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 3023 }); 3024 } 3025 } catch (exception) { 3026 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 3027 } 3028 } 3029}; 3030``` 3031 3032### isWindowShowing<sup>9+</sup> 3033 3034isWindowShowing(): boolean 3035 3036Checks whether this window is displayed. 3037 3038**System capability**: SystemCapability.WindowManager.WindowManager.Core 3039 3040**Return value** 3041 3042| Type| Description| 3043| ------- | ------------------------------------------------------------------ | 3044| boolean | Whether the window is displayed. The value **true** means that the window is displayed, and **false** means the opposite.| 3045 3046**Error codes** 3047 3048For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3049 3050| ID| Error Message| 3051| ------- | ------------------------------ | 3052| 1300002 | This window state is abnormal. | 3053 3054**Example** 3055 3056```ts 3057try { 3058 let data = windowClass.isWindowShowing(); 3059 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 3060} catch (exception) { 3061 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(exception)); 3062} 3063``` 3064 3065### on('windowSizeChange')<sup>7+</sup> 3066 3067on(type: 'windowSizeChange', callback: Callback<Size>): void 3068 3069Subscribes to the window size change event. 3070 3071**System capability**: SystemCapability.WindowManager.WindowManager.Core 3072 3073**Parameters** 3074 3075| Name | Type | Mandatory| Description | 3076| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3077| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 3078| callback | Callback<[Size](#size7)> | Yes | Callback used to return the window size. | 3079 3080**Example** 3081 3082```ts 3083try { 3084 windowClass.on('windowSizeChange', (data) => { 3085 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 3086 }); 3087} catch (exception) { 3088 console.error('Failed to enable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 3089} 3090``` 3091 3092### off('windowSizeChange')<sup>7+</sup> 3093 3094off(type: 'windowSizeChange', callback?: Callback<Size>): void 3095 3096Unsubscribes from the window size change event. 3097 3098**System capability**: SystemCapability.WindowManager.WindowManager.Core 3099 3100**Parameters** 3101 3102| Name | Type | Mandatory| Description | 3103| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3104| type | string | Yes | Event type. The value is fixed at **'windowSizeChange'**, indicating the window size change event.| 3105| callback | Callback<[Size](#size7)> | No | Callback used to return the window size. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3106 3107**Example** 3108 3109```ts 3110try { 3111 windowClass.off('windowSizeChange'); 3112} catch (exception) { 3113 console.error('Failed to disable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 3114} 3115``` 3116 3117### on('avoidAreaChange')<sup>9+</sup> 3118 3119on(type: 'avoidAreaChange', callback: Callback<{ type: AvoidAreaType, area: AvoidArea}>): void 3120 3121Subscribes to the event indicating changes to the area where the window cannot be displayed. 3122 3123**System capability**: SystemCapability.WindowManager.WindowManager.Core 3124 3125**Parameters** 3126 3127| Name | Type | Mandatory| Description | 3128| -------- |------------------------------------------------------------------| ---- |--------------------------------------| 3129| 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.| 3130| callback | Callback<{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }> | Yes | Callback used to return the area and area type.| 3131 3132**Example** 3133 3134```ts 3135try { 3136 windowClass.on('avoidAreaChange', (data) => { 3137 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 3138 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 3139 }); 3140} catch (exception) { 3141 console.error('Failed to enable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 3142} 3143``` 3144 3145### off('avoidAreaChange')<sup>9+</sup> 3146 3147off(type: 'avoidAreaChange', callback?: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void 3148 3149Unsubscribes from the event indicating changes to the area where the window cannot be displayed. 3150 3151**System capability**: SystemCapability.WindowManager.WindowManager.Core 3152 3153**Parameters** 3154 3155| Name | Type | Mandatory | Description | 3156| -------- |-----------------------------------------------------------------------------|-----|------------------------------------| 3157| 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.| 3158| callback | Callback<{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }> | No | Callback used to return the area and area type. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 3159 3160**Example** 3161 3162```ts 3163try { 3164 windowClass.off('avoidAreaChange'); 3165} catch (exception) { 3166 console.error('Failed to disable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 3167} 3168``` 3169 3170### on('keyboardHeightChange')<sup>7+</sup> 3171 3172on(type: 'keyboardHeightChange', callback: Callback<number>): void 3173 3174Subscribes to the event indicating soft keyboard height changes in the input method panel in fixed state. Since API version 10, the input method panel can be set to the fixed or floating state. For details, see [Input Method Service](js-apis-inputmethodengine.md#changeflag10). 3175 3176**System capability**: SystemCapability.WindowManager.WindowManager.Core 3177 3178**Parameters** 3179 3180| Name | Type | Mandatory| Description | 3181| -------- | ------------------- | ---- |-------------------------------------------| 3182| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 3183| callback | Callback<number> | Yes | Callback used to return the current keyboard height, which is an integer. | 3184 3185**Example** 3186 3187```ts 3188try { 3189 windowClass.on('keyboardHeightChange', (data) => { 3190 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 3191 }); 3192} catch (exception) { 3193 console.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 3194} 3195``` 3196 3197### off('keyboardHeightChange')<sup>7+</sup> 3198 3199off(type: 'keyboardHeightChange', callback?: Callback<number>): void 3200 3201Unsubscribes from the event indicating soft keyboard height changes in the input method panel in fixed state. Since API version 10, the input method panel can be set to the fixed or floating state. For details, see [Input Method Service](js-apis-inputmethodengine.md#changeflag10). 3202 3203**System capability**: SystemCapability.WindowManager.WindowManager.Core 3204 3205**Parameters** 3206 3207| Name | Type | Mandatory| Description | 3208| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3209| type | string | Yes | Event type. The value is fixed at **'keyboardHeightChange'**, indicating the keyboard height change event.| 3210| callback | Callback<number> | No | Callback used to return the current keyboard height, which is an integer. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3211 3212**Example** 3213 3214```ts 3215try { 3216 windowClass.off('keyboardHeightChange'); 3217} catch (exception) { 3218 console.error('Failed to disable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 3219} 3220``` 3221 3222### on('touchOutside')<sup>9+</sup> 3223 3224on(type: 'touchOutside', callback: Callback<void>): void 3225 3226Subscribes to the click event outside this window. 3227 3228**System API**: This is a system API. 3229 3230**System capability**: SystemCapability.WindowManager.WindowManager.Core 3231 3232**Parameters** 3233 3234| Name | Type | Mandatory| Description | 3235| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3236| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the click event outside this window.| 3237| callback | Callback<void> | Yes | Callback used to return the click event outside this window. | 3238 3239**Example** 3240 3241```ts 3242try { 3243 windowClass.on('touchOutside', () => { 3244 console.info('touch outside'); 3245 }); 3246} catch (exception) { 3247 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3248} 3249``` 3250 3251### off('touchOutside')<sup>9+</sup> 3252 3253off(type: 'touchOutside', callback?: Callback<void>): void 3254 3255Unsubscribes from the click event outside this window. 3256 3257**System API**: This is a system API. 3258 3259**System capability**: SystemCapability.WindowManager.WindowManager.Core 3260 3261**Parameters** 3262 3263| Name | Type | Mandatory| Description | 3264| -------- |----------------------| ---- |--------------------------------------| 3265| type | string | Yes | Event type. The value is fixed at **'touchOutside'**, indicating the click event outside this window.| 3266| callback | Callback<void> | No | Callback used to return the click event outside this window. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3267 3268**Example** 3269 3270```ts 3271try { 3272 windowClass.off('touchOutside'); 3273} catch (exception) { 3274 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3275} 3276``` 3277 3278### on('screenshot')<sup>9+</sup> 3279 3280on(type: 'screenshot', callback: Callback<void>): void 3281 3282Subscribes to the screenshot event. 3283 3284**System capability**: SystemCapability.WindowManager.WindowManager.Core 3285 3286**Parameters** 3287 3288| Name | Type | Mandatory| Description | 3289| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3290| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| 3291| callback | Callback<void> | Yes | Callback invoked when a screenshot event occurs. | 3292 3293**Example** 3294 3295```ts 3296try { 3297 windowClass.on('screenshot', () => { 3298 console.info('screenshot happened'); 3299 }); 3300} catch (exception) { 3301 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3302} 3303``` 3304 3305### off('screenshot')<sup>9+</sup> 3306 3307off(type: 'screenshot', callback?: Callback<void>): void 3308 3309Unsubscribes from the screenshot event. 3310 3311**System capability**: SystemCapability.WindowManager.WindowManager.Core 3312 3313**Parameters** 3314 3315| Name | Type | Mandatory| Description | 3316| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3317| type | string | Yes | Event type. The value is fixed at **'screenshot'**, indicating the screenshot event.| 3318| callback | Callback<void> | No | Callback invoked when a screenshot event occurs. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 3319 3320**Example** 3321 3322```ts 3323let callback = () => { 3324 console.info('screenshot happened'); 3325}; 3326try { 3327 windowClass.on('screenshot', callback); 3328} catch (exception) { 3329 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3330} 3331try { 3332 windowClass.off('screenshot', callback); 3333 // If multiple callbacks are enabled in on(), they will all be disabled. 3334 windowClass.off('screenshot'); 3335} catch (exception) { 3336 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3337} 3338``` 3339 3340### on('dialogTargetTouch')<sup>10+</sup> 3341 3342on(type: 'dialogTargetTouch', callback: Callback<void>): void 3343 3344Subscribes to the click event of the target window in the modal window mode. 3345 3346**System capability**: SystemCapability.WindowManager.WindowManager.Core 3347 3348**Parameters** 3349 3350| Name | Type | Mandatory| Description | 3351| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3352| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click event of the target window in the modal window mode.| 3353| callback | Callback<void>| Yes | Callback invoked when the click event occurs in the target window of the modal window mode.| 3354 3355**Example** 3356 3357```ts 3358try { 3359 windowClass.on('dialogTargetTouch', () => { 3360 console.info('touch dialog target'); 3361 }); 3362} catch (exception) { 3363 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3364} 3365``` 3366 3367### off('dialogTargetTouch')<sup>10+</sup> 3368 3369off(type: 'dialogTargetTouch', callback?: Callback<void>): void 3370 3371Unsubscribes from the click event of the target window in the modal window mode. 3372 3373**System capability**: SystemCapability.WindowManager.WindowManager.Core 3374 3375**Parameters** 3376 3377| Name | Type | Mandatory| Description | 3378| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3379| type | string | Yes | Event type. The value is fixed at **'dialogTargetTouch'**, indicating the click event of the target window in the modal window mode.| 3380| callback | Callback<void> | No | Callback invoked when the click event occurs in the target window of the modal window mode. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled.| 3381 3382**Example** 3383 3384```ts 3385try { 3386 windowClass.off('dialogTargetTouch'); 3387} catch (exception) { 3388 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3389} 3390``` 3391 3392### on('windowEvent')<sup>10+</sup> 3393 3394on(type: 'windowEvent', callback: Callback<WindowEventType>): void 3395 3396Subscribes to the window lifecycle change event. 3397 3398**System capability**: SystemCapability.WindowManager.WindowManager.Core 3399 3400**Parameters** 3401 3402| Name | Type | Mandatory| Description | 3403| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3404| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 3405| callback | Callback<[WindowEventType](#windoweventtype10)> | Yes | Callback used to return the window lifecycle state. | 3406 3407**Example** 3408 3409```ts 3410try { 3411 windowClass.on('windowEvent', (data) => { 3412 console.info('Window event happened. Event:' + JSON.stringify(data)); 3413 }); 3414} catch (exception) { 3415 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3416} 3417``` 3418 3419### off('windowEvent')<sup>10+</sup> 3420 3421off(type: 'windowEvent', callback?: Callback<WindowEventType >): void 3422 3423Unsubscribes from the window lifecycle change event. 3424 3425**System capability**: SystemCapability.WindowManager.WindowManager.Core 3426 3427**Parameters** 3428 3429| Name | Type | Mandatory| Description | 3430| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3431| type | string | Yes | Event type. The value is fixed at **'windowEvent'**, indicating the window lifecycle change event.| 3432| callback | Callback<[WindowEventType](#windoweventtype10)> | No | Callback used to return the window lifecycle state. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 3433 3434**Example** 3435 3436```ts 3437try { 3438 windowClass.off('windowEvent'); 3439} catch (exception) { 3440 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3441} 3442``` 3443 3444### bindDialogTarget<sup>9+</sup> 3445 3446bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 3447 3448Binds 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. 3449 3450**System API**: This is a system API. 3451 3452**System capability**: SystemCapability.WindowManager.WindowManager.Core 3453 3454**Parameters** 3455 3456| Name | Type | Mandatory| Description | 3457| ----------- | ------------------------- | ---- | -------------------- | 3458| token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | Yes | Token of the target window.| 3459| deathCallback | Callback<void> | Yes | Callback used to listen for modal window destruction events.| 3460| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3461 3462**Error codes** 3463 3464For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3465 3466| ID| Error Message| 3467| ------- | -------------------------------------------- | 3468| 1300002 | This window state is abnormal. | 3469| 1300003 | This window manager service works abnormally. | 3470 3471**Example** 3472 3473```ts 3474import rpc from '@ohos.rpc'; 3475import { BusinessError } from '@ohos.base'; 3476 3477class MyDeathRecipient { 3478 onRemoteDied() { 3479 console.log('server died'); 3480 } 3481} 3482 3483class TestRemoteObject extends rpc.RemoteObject { 3484 constructor(descriptor: string) { 3485 super(descriptor); 3486 } 3487 3488 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3489 return true; 3490 } 3491 3492 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3493 return true; 3494 } 3495 3496 isObjectDead(): boolean { 3497 return false; 3498 } 3499} 3500 3501let token: TestRemoteObject = new TestRemoteObject('testObject'); 3502let windowClass: window.Window | null = null; 3503let config: window.Configuration = { name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; 3504try { 3505 window.createWindow(config, (err: BusinessError, data) => { 3506 let errCode: number = err.code; 3507 if (errCode) { 3508 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3509 return; 3510 } 3511 windowClass = data; 3512 }); 3513 windowClass.bindDialogTarget(token, () => { 3514 console.info('Dialog Window Need Destroy.'); 3515 }, (err: BusinessError) => { 3516 let errCode: number = err.code; 3517 if (errCode) { 3518 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3519 return; 3520 } 3521 console.info('Succeeded in binding dialog target.'); 3522 }); 3523} catch (exception) { 3524 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception)); 3525} 3526``` 3527 3528### bindDialogTarget<sup>9+</sup> 3529 3530bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void> 3531 3532Binds 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. 3533 3534**System API**: This is a system API. 3535 3536**System capability**: SystemCapability.WindowManager.WindowManager.Core 3537 3538**Parameters** 3539 3540| Name | Type | Mandatory| Description | 3541| ----------- | ------------------------- | ---- | -------------------- | 3542| token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | Yes | Token of the target window.| 3543| deathCallback | Callback<void> | Yes | Callback used to listen for modal window destruction events.| 3544 3545**Return value** 3546 3547| Type | Description | 3548| ------------------- | ------------------------- | 3549| Promise<void> | Promise that returns no value.| 3550 3551**Error codes** 3552 3553For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3554 3555| ID| Error Message| 3556| ------- | -------------------------------------------- | 3557| 1300002 | This window state is abnormal. | 3558| 1300003 | This window manager service works abnormally. | 3559 3560**Example** 3561 3562```ts 3563import rpc from '@ohos.rpc'; 3564import { BusinessError } from '@ohos.base'; 3565 3566class MyDeathRecipient { 3567 onRemoteDied() { 3568 console.log('server died'); 3569 } 3570} 3571 3572class TestRemoteObject extends rpc.RemoteObject { 3573 constructor(descriptor: string) { 3574 super(descriptor); 3575 } 3576 3577 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3578 return true; 3579 } 3580 3581 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3582 return true; 3583 } 3584 3585 isObjectDead(): boolean { 3586 return false; 3587 } 3588} 3589 3590let token: TestRemoteObject = new TestRemoteObject('testObject'); 3591let windowClass: window.Window | null = null; 3592let config: window.Configuration = { 3593 name: "dialogWindow", 3594 windowType: window.WindowType.TYPE_DIALOG, 3595 ctx: this.context 3596}; 3597try { 3598 window.createWindow(config, (err: BusinessError, data) => { 3599 const errCode: number = err.code; 3600 if (errCode) { 3601 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3602 return; 3603 } 3604 windowClass = data; 3605 }); 3606 let promise = windowClass.bindDialogTarget(token, () => { 3607 console.info('Dialog Window Need Destroy.'); 3608 }); 3609 promise.then(() => { 3610 console.info('Succeeded in binding dialog target.'); 3611 }).catch((err: BusinessError) => { 3612 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3613 }); 3614} catch (exception) { 3615 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception)); 3616} 3617``` 3618 3619### bindDialogTarget<sup>9+</sup> 3620 3621bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 3622 3623Binds 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. 3624 3625**System API**: This is a system API. 3626 3627**System capability**: SystemCapability.WindowManager.WindowManager.Core 3628 3629**Parameters** 3630 3631| Name | Type | Mandatory| Description | 3632| ----------- | ------------------------- | ---- | -------------------- | 3633| requestInfo | [dialogRequest.RequestInfo](js-apis-app-ability-dialogRequest.md#requestinfo) | Yes | **RequestInfo** of the target window.| 3634| deathCallback | Callback<void> | Yes | Callback used to listen for modal window destruction events.| 3635| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3636 3637**Error codes** 3638 3639For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3640 3641| ID| Error Message| 3642| ------- | -------------------------------------------- | 3643| 1300002 | This window state is abnormal. | 3644| 1300003 | This window manager service works abnormally. | 3645 3646**Example** 3647 3648```ts 3649import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; 3650import dialogRequest from '@ohos.app.ability.dialogRequest'; 3651import Want from '@ohos.app.ability.Want'; 3652import { BusinessError } from '@ohos.base'; 3653 3654export default class ServiceExtAbility extends ServiceExtensionAbility { 3655 onRequest(want: Want, startId: number) { 3656 console.info('onRequest'); 3657 let windowClass: window.Window | null = null; 3658 let config: window.Configuration = { 3659 name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context 3660 }; 3661 try { 3662 window.createWindow(config, (err: BusinessError, data) => { 3663 let errCode: number = err.code; 3664 if (errCode) { 3665 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3666 return; 3667 } 3668 windowClass = data; 3669 }); 3670 let requestInfo = dialogRequest.getRequestInfo(want) 3671 windowClass.bindDialogTarget(requestInfo, () => { 3672 console.info('Dialog Window Need Destroy.'); 3673 }, (err: BusinessError) => { 3674 let errCode: number = err.code; 3675 if (errCode) { 3676 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3677 return; 3678 } 3679 console.info('Succeeded in binding dialog target.'); 3680 }); 3681 } catch (err) { 3682 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)) 3683 } 3684 } 3685} 3686``` 3687 3688### bindDialogTarget<sup>9+</sup> 3689 3690bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>): Promise<void> 3691 3692Binds 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. 3693 3694**System API**: This is a system API. 3695 3696**System capability**: SystemCapability.WindowManager.WindowManager.Core 3697 3698**Parameters** 3699 3700| Name | Type | Mandatory| Description | 3701| ----------- | ------------------------- | ---- | -------------------- | 3702| requestInfo | [dialogRequest.RequestInfo](js-apis-app-ability-dialogRequest.md#requestinfo) | Yes | **RequestInfo** of the target window.| 3703| deathCallback | Callback<void> | Yes | Callback used to listen for modal window destruction events.| 3704 3705**Return value** 3706 3707| Type | Description | 3708| ------------------- | ------------------------- | 3709| Promise<void> | Promise that returns no value.| 3710 3711**Error codes** 3712 3713For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3714 3715| ID| Error Message| 3716| ------- | -------------------------------------------- | 3717| 1300002 | This window state is abnormal. | 3718| 1300003 | This window manager service works abnormally. | 3719 3720**Example** 3721 3722```ts 3723import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; 3724import dialogRequest from '@ohos.app.ability.dialogRequest'; 3725import Want from '@ohos.app.ability.Want'; 3726import { BusinessError } from '@ohos.base'; 3727 3728export default class ServiceExtAbility extends ServiceExtensionAbility { 3729 onRequest(want: Want, startId: number) { 3730 console.info('onRequest'); 3731 let windowClass: window.Window | null = null; 3732 let config: window.Configuration = { 3733 name: "dialogWindow", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context 3734 }; 3735 try { 3736 window.createWindow(config, (err: BusinessError, data) => { 3737 const errCode: number = err.code; 3738 if (errCode) { 3739 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3740 return; 3741 } 3742 windowClass = data; 3743 }); 3744 let requestInfo = dialogRequest.getRequestInfo(want) 3745 let promise = windowClass.bindDialogTarget(requestInfo, () => { 3746 console.info('Dialog Window Need Destroy.'); 3747 }); 3748 promise.then(() => { 3749 console.info('Succeeded in binding dialog target.'); 3750 }).catch((err: BusinessError) => { 3751 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3752 }); 3753 } catch (err) { 3754 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)) 3755 } 3756 } 3757} 3758``` 3759 3760### isWindowSupportWideGamut<sup>9+</sup> 3761 3762isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 3763 3764Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 3765 3766**System capability**: SystemCapability.WindowManager.WindowManager.Core 3767 3768**Parameters** 3769 3770| Name| Type| Mandatory| Description| 3771| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 3772| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite.| 3773 3774**Error codes** 3775 3776For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3777 3778| ID| Error Message| 3779| ------- | ------------------------------ | 3780| 1300002 | This window state is abnormal. | 3781 3782**Example** 3783 3784```ts 3785import { BusinessError } from '@ohos.base'; 3786 3787windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 3788 const errCode: number = err.code; 3789 if (errCode) { 3790 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 3791 return; 3792 } 3793 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 3794}); 3795``` 3796 3797### isWindowSupportWideGamut<sup>9+</sup> 3798 3799isWindowSupportWideGamut(): Promise<boolean> 3800 3801Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 3802 3803**System capability**: SystemCapability.WindowManager.WindowManager.Core 3804 3805**Return value** 3806 3807| Type| Description| 3808| ---------------------- | ------------------------------------------------------------------------------------ | 3809| Promise<boolean> | Promise used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite.| 3810 3811**Error codes** 3812 3813For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3814 3815| ID| Error Message| 3816| ------- | ------------------------------ | 3817| 1300002 | This window state is abnormal. | 3818 3819**Example** 3820 3821```ts 3822import { BusinessError } from '@ohos.base'; 3823 3824let promise = windowClass.isWindowSupportWideGamut(); 3825promise.then((data) => { 3826 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 3827}).catch((err: BusinessError) => { 3828 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 3829}); 3830``` 3831 3832### setWindowColorSpace<sup>9+</sup> 3833 3834setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 3835 3836Sets a color space for this window. This API uses an asynchronous callback to return the result. 3837 3838**System capability**: SystemCapability.WindowManager.WindowManager.Core 3839 3840**Parameters** 3841 3842| Name| Type| Mandatory| Description| 3843| ---------- | ------------------------- | -- | ----------- | 3844| colorSpace | [ColorSpace](#colorspace8) | Yes| Color space to set.| 3845| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3846 3847**Error codes** 3848 3849For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3850 3851| ID| Error Message| 3852| ------- | ------------------------------ | 3853| 1300002 | This window state is abnormal. | 3854 3855**Example** 3856 3857```ts 3858import { BusinessError } from '@ohos.base'; 3859 3860try { 3861 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 3862 const errCode: number = err.code; 3863 if (errCode) { 3864 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 3865 return; 3866 } 3867 console.info('Succeeded in setting window colorspace.'); 3868 }); 3869} catch (exception) { 3870 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3871} 3872``` 3873 3874### setWindowColorSpace<sup>9+</sup> 3875 3876setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 3877 3878Sets a color space for this window. This API uses a promise to return the result. 3879 3880**System capability**: SystemCapability.WindowManager.WindowManager.Core 3881 3882**Parameters** 3883 3884| Name| Type| Mandatory| Description| 3885| ---------- | ------------------------- | -- | ------------- | 3886| colorSpace | [ColorSpace](#colorspace8) | Yes| Color space to set.| 3887 3888**Return value** 3889 3890| Type| Description| 3891| ------------------- | ------------------------ | 3892| Promise<void> | Promise that returns no value.| 3893 3894**Error codes** 3895 3896For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3897 3898| ID| Error Message| 3899| ------- | ------------------------------ | 3900| 1300002 | This window state is abnormal. | 3901 3902**Example** 3903 3904```ts 3905import { BusinessError } from '@ohos.base'; 3906 3907try { 3908 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 3909 promise.then(() => { 3910 console.info('Succeeded in setting window colorspace.'); 3911 }).catch((err: BusinessError) => { 3912 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 3913 }); 3914} catch (exception) { 3915 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3916} 3917``` 3918 3919### getWindowColorSpace<sup>9+</sup> 3920 3921getWindowColorSpace(): ColorSpace 3922 3923Obtains the color space of this window. 3924 3925**System capability**: SystemCapability.WindowManager.WindowManager.Core 3926 3927**Return value** 3928 3929| Type| Description| 3930| ------------------------- | ------------- | 3931| [ColorSpace](#colorspace8) | Color space obtained.| 3932 3933**Error codes** 3934 3935For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3936 3937| ID| Error Message| 3938| ------- | ------------------------------ | 3939| 1300002 | This window state is abnormal. | 3940 3941**Example** 3942 3943```ts 3944let colorSpace = windowClass.getWindowColorSpace(); 3945``` 3946 3947### setWindowBackgroundColor<sup>9+</sup> 3948 3949setWindowBackgroundColor(color: string): void 3950 3951Sets the background color for this window. In the stage model, this API must be used after the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 3952 3953**System capability**: SystemCapability.WindowManager.WindowManager.Core 3954 3955**Parameters** 3956 3957| Name| Type| Mandatory| Description| 3958| ----- | ------ | -- | ----------------------------------------------------------------------- | 3959| color | string | Yes| Background color to set. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**.| 3960 3961**Error codes** 3962 3963For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 3964 3965| ID| Error Message| 3966| ------- | ------------------------------ | 3967| 1300002 | This window state is abnormal. | 3968 3969**Example** 3970 3971```ts 3972let color: string = '#00ff33'; 3973try { 3974 windowClass.setWindowBackgroundColor(color); 3975} catch (exception) { 3976 console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception)); 3977} 3978``` 3979 3980### setWindowBrightness<sup>9+</sup> 3981 3982setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 3983 3984Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. 3985 3986When the screen brightness setting for the window takes effect, Control Panel cannot adjust the system screen brightness. It can do so only after the window screen brightness is restored to the default value. 3987 3988**System capability**: SystemCapability.WindowManager.WindowManager.Core 3989 3990**Parameters** 3991 3992| Name| Type| Mandatory| Description | 3993| ---------- | ------------------------- | -- |-------------------------------------------| 3994| brightness | number | Yes| Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 3995| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 3996 3997**Error codes** 3998 3999For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4000 4001| ID| Error Message| 4002| ------- | -------------------------------------------- | 4003| 1300002 | This window state is abnormal. | 4004| 1300003 | This window manager service works abnormally. | 4005 4006**Example** 4007 4008```ts 4009import { BusinessError } from '@ohos.base'; 4010 4011let brightness: number = 1; 4012try { 4013 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 4014 const errCode: number = err.code; 4015 if (errCode) { 4016 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 4017 return; 4018 } 4019 console.info('Succeeded in setting the brightness.'); 4020 }); 4021} catch (exception) { 4022 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 4023} 4024``` 4025 4026### setWindowBrightness<sup>9+</sup> 4027 4028setWindowBrightness(brightness: number): Promise<void> 4029 4030Sets the screen brightness for this window. This API uses a promise to return the result. 4031 4032When the screen brightness setting for the window takes effect, Control Panel cannot adjust the system screen brightness. It can do so only after the window screen brightness is restored to the default value. 4033 4034**System capability**: SystemCapability.WindowManager.WindowManager.Core 4035 4036**Parameters** 4037 4038| Name| Type| Mandatory| Description | 4039| ---------- | ------ | -- |----------------------------------------| 4040| brightness | number | Yes| Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness.| 4041 4042**Return value** 4043 4044| Type| Description| 4045| ------------------- | ------------------------ | 4046| Promise<void> | Promise that returns no value.| 4047 4048**Error codes** 4049 4050For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4051 4052| ID| Error Message| 4053| ------- | -------------------------------------------- | 4054| 1300002 | This window state is abnormal. | 4055| 1300003 | This window manager service works abnormally. | 4056 4057**Example** 4058 4059```ts 4060import { BusinessError } from '@ohos.base'; 4061 4062let brightness: number = 1; 4063try { 4064 let promise = windowClass.setWindowBrightness(brightness); 4065 promise.then(() => { 4066 console.info('Succeeded in setting the brightness.'); 4067 }).catch((err: BusinessError) => { 4068 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 4069 }); 4070} catch (exception) { 4071 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 4072} 4073``` 4074 4075### setWindowFocusable<sup>9+</sup> 4076 4077setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 4078 4079Sets whether this window can gain focus. This API uses an asynchronous callback to return the result. 4080 4081**System capability**: SystemCapability.WindowManager.WindowManager.Core 4082 4083**Parameters** 4084 4085| Name| Type| Mandatory| Description| 4086| ----------- | ------------------------- | -- | ------------------------------------------------------- | 4087| isFocusable | boolean | Yes| Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite.| 4088| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 4089 4090**Error codes** 4091 4092For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4093 4094| ID| Error Message| 4095| ------- | -------------------------------------------- | 4096| 1300002 | This window state is abnormal. | 4097| 1300003 | This window manager service works abnormally. | 4098 4099**Example** 4100 4101```ts 4102import { BusinessError } from '@ohos.base'; 4103 4104let isFocusable: boolean = true; 4105try { 4106 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 4107 const errCode: number = err.code; 4108 if (errCode) { 4109 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 4110 return; 4111 } 4112 console.info('Succeeded in setting the window to be focusable.'); 4113 }); 4114} catch (exception) { 4115 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 4116} 4117``` 4118 4119### setWindowFocusable<sup>9+</sup> 4120 4121setWindowFocusable(isFocusable: boolean): Promise<void> 4122 4123Sets whether this window can gain focus. This API uses a promise to return the result. 4124 4125**System capability**: SystemCapability.WindowManager.WindowManager.Core 4126 4127**Parameters** 4128 4129| Name| Type| Mandatory| Description| 4130| ----------- | ------- | -- | -------------------------------------------------------- | 4131| isFocusable | boolean | Yes| Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 4132 4133**Return value** 4134 4135| Type| Description| 4136| ------------------- | ------------------------ | 4137| Promise<void> | Promise that returns no value.| 4138 4139**Error codes** 4140 4141For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4142 4143| ID| Error Message| 4144| ------- | -------------------------------------------- | 4145| 1300002 | This window state is abnormal. | 4146| 1300003 | This window manager service works abnormally. | 4147 4148**Example** 4149 4150```ts 4151import { BusinessError } from '@ohos.base'; 4152 4153let isFocusable: boolean = true; 4154try { 4155 let promise = windowClass.setWindowFocusable(isFocusable); 4156 promise.then(() => { 4157 console.info('Succeeded in setting the window to be focusable.'); 4158 }).catch((err: BusinessError) => { 4159 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 4160 }); 4161} catch (exception) { 4162 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 4163} 4164``` 4165 4166### setWindowKeepScreenOn<sup>9+</sup> 4167 4168setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 4169 4170Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 4171 4172**System capability**: SystemCapability.WindowManager.WindowManager.Core 4173 4174**Parameters** 4175 4176| Name| Type| Mandatory| Description| 4177| -------------- | ------------------------- | -- | ---------------------------------------------------- | 4178| isKeepScreenOn | boolean | Yes| Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite. | 4179| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 4180 4181**Error codes** 4182 4183For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4184 4185| ID| Error Message| 4186| ------- | -------------------------------------------- | 4187| 1300002 | This window state is abnormal. | 4188| 1300003 | This window manager service works abnormally. | 4189 4190**Example** 4191 4192```ts 4193import { BusinessError } from '@ohos.base'; 4194 4195let isKeepScreenOn: boolean = true; 4196try { 4197 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 4198 const errCode: number = err.code; 4199 if (errCode) { 4200 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 4201 return; 4202 } 4203 console.info('Succeeded in setting the screen to be always on.'); 4204 }); 4205} catch (exception) { 4206 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 4207} 4208``` 4209 4210### setWindowKeepScreenOn<sup>9+</sup> 4211 4212setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 4213 4214Sets whether to keep the screen always on. This API uses a promise to return the result. 4215 4216**System capability**: SystemCapability.WindowManager.WindowManager.Core 4217 4218**Parameters** 4219 4220| Name| Type| Mandatory| Description| 4221| -------------- | ------- | -- | --------------------------------------------------- | 4222| isKeepScreenOn | boolean | Yes| Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite.| 4223 4224**Return value** 4225 4226| Type| Description| 4227| ------------------- | ------------------------ | 4228| Promise<void> | Promise that returns no value.| 4229 4230**Error codes** 4231 4232For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4233 4234| ID| Error Message| 4235| ------- | -------------------------------------------- | 4236| 1300002 | This window state is abnormal. | 4237| 1300003 | This window manager service works abnormally. | 4238 4239**Example** 4240 4241```ts 4242import { BusinessError } from '@ohos.base'; 4243 4244let isKeepScreenOn: boolean = true; 4245try { 4246 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 4247 promise.then(() => { 4248 console.info('Succeeded in setting the screen to be always on.'); 4249 }).catch((err: BusinessError) => { 4250 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 4251 }); 4252} catch (exception) { 4253 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 4254} 4255``` 4256 4257### setWakeUpScreen()<sup>9+</sup> 4258 4259setWakeUpScreen(wakeUp: boolean): void 4260 4261Wakes up the screen. 4262 4263**System API**: This is a system API. 4264 4265**System capability**: SystemCapability.WindowManager.WindowManager.Core 4266 4267**Parameters** 4268 4269| Name | Type | Mandatory| Description | 4270| ---------------- | ------- | ---- | ---------------------------- | 4271| wakeUp | boolean | Yes | Whether to wake up the screen. The value **true** means to wake up the screen, and **false** means the opposite. | 4272 4273**Error codes** 4274 4275For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4276 4277| ID| Error Message| 4278| ------- | -------------------------------------------- | 4279| 1300002 | This window state is abnormal. | 4280| 1300003 | This window manager service works abnormally. | 4281 4282**Example** 4283 4284```ts 4285let wakeUp: boolean = true; 4286try { 4287 windowClass.setWakeUpScreen(wakeUp); 4288} catch (exception) { 4289 console.error('Failed to wake up the screen. Cause: ' + JSON.stringify(exception)); 4290} 4291``` 4292 4293### setWindowPrivacyMode<sup>9+</sup> 4294 4295setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 4296 4297Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 4298 4299A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 4300 4301**System capability**: SystemCapability.WindowManager.WindowManager.Core 4302 4303**Required permissions**: ohos.permission.PRIVACY_WINDOW 4304 4305**Parameters** 4306 4307| Name| Type| Mandatory| Description| 4308| ------------- | ------------------------- | -- | ------------------------------------------------------ | 4309| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. The value **true** means that the window is in privacy mode, and **false** means the opposite. | 4310| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 4311 4312**Error codes** 4313 4314For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4315 4316| ID| Error Message| 4317| ------- | ------------------------------ | 4318| 1300002 | This window state is abnormal. | 4319 4320**Example** 4321 4322```ts 4323import { BusinessError } from '@ohos.base'; 4324 4325let isPrivacyMode: boolean = true; 4326try { 4327 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 4328 const errCode: number = err.code; 4329 if (errCode) { 4330 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 4331 return; 4332 } 4333 console.info('Succeeded in setting the window to privacy mode.'); 4334 }); 4335} catch (exception) { 4336 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 4337} 4338``` 4339 4340### setWindowPrivacyMode<sup>9+</sup> 4341 4342setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 4343 4344Sets whether this window is in privacy mode. This API uses a promise to return the result. 4345 4346A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 4347 4348**System capability**: SystemCapability.WindowManager.WindowManager.Core 4349 4350**Required permissions**: ohos.permission.PRIVACY_WINDOW 4351 4352**Parameters** 4353 4354| Name| Type| Mandatory| Description| 4355| ------------- | ------- | -- | ----------------------------------------------------- | 4356| isPrivacyMode | boolean | Yes| Whether the window is in privacy mode. The value **true** means that the window is in privacy mode, and **false** means the opposite.| 4357 4358**Return value** 4359 4360| Type| Description| 4361| ------------------- | ------------------------ | 4362| Promise<void> | Promise that returns no value.| 4363 4364**Error codes** 4365 4366For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4367 4368| ID| Error Message| 4369| ------- | ------------------------------ | 4370| 1300002 | This window state is abnormal. | 4371 4372**Example** 4373 4374```ts 4375import { BusinessError } from '@ohos.base'; 4376 4377let isPrivacyMode: boolean = true; 4378try { 4379 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 4380 promise.then(() => { 4381 console.info('Succeeded in setting the window to privacy mode.'); 4382 }).catch((err: BusinessError) => { 4383 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 4384 }); 4385} catch (exception) { 4386 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 4387} 4388``` 4389 4390### setSnapshotSkip<sup>9+</sup> 4391setSnapshotSkip(isSkip: boolean): void 4392 4393Sets whether to ignore this window during screen capturing or recording. This API is generally used in scenarios where screen capture or recording is disabled. 4394 4395**System API**: This is a system API. 4396 4397**System capability**: SystemCapability.WindowManager.WindowManager.Core 4398 4399**Parameters** 4400 4401| Name | Type | Mandatory| Description | 4402| ------------- | ------- | ---- | -------------------- | 4403| isSkip | boolean | Yes | Whether to ignore the window. The default value is **false**.<br>The value **true** means that the window is ignored, and **false** means the opposite.<br>| 4404 4405**Error codes** 4406 4407For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4408 4409| ID| Error Message| 4410| ------- | ------------------------------ | 4411| 1300002 | This window state is abnormal. | 4412 4413```ts 4414let windowClass: window.Window | null = null; 4415let isSkip: boolean = true; 4416try { 4417 windowClass.setSnapshotSkip(isSkip); 4418} catch (exception) { 4419 console.error('Failed to Skip. Cause: ' + JSON.stringify(exception)); 4420} 4421``` 4422 4423### setWindowTouchable<sup>9+</sup> 4424 4425setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 4426 4427Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 4428 4429**System capability**: SystemCapability.WindowManager.WindowManager.Core 4430 4431**Parameters** 4432 4433| Name| Type| Mandatory| Description| 4434| ----------- | ------------------------- | -- | ----------------------------------------------- | 4435| isTouchable | boolean | Yes| Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 4436| callback | AsyncCallback<void> | Yes| Callback used to return the result. | 4437 4438**Error codes** 4439 4440For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4441 4442| ID| Error Message| 4443| ------- | -------------------------------------------- | 4444| 1300002 | This window state is abnormal. | 4445| 1300003 | This window manager service works abnormally. | 4446 4447**Example** 4448 4449```ts 4450import { BusinessError } from '@ohos.base'; 4451 4452let isTouchable = true; 4453try { 4454 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 4455 const errCode: number = err.code; 4456 if (errCode) { 4457 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 4458 return; 4459 } 4460 console.info('Succeeded in setting the window to be touchable.'); 4461 }); 4462} catch (exception) { 4463 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 4464} 4465``` 4466 4467### setWindowTouchable<sup>9+</sup> 4468 4469setWindowTouchable(isTouchable: boolean): Promise<void> 4470 4471Sets whether this window is touchable. This API uses a promise to return the result. 4472 4473**System capability**: SystemCapability.WindowManager.WindowManager.Core 4474 4475**Parameters** 4476 4477| Name| Type| Mandatory| Description| 4478| ----------- | ------- | -- | ----------------------------------------------- | 4479| isTouchable | boolean | Yes| Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite.| 4480 4481**Return value** 4482 4483| Type| Description| 4484| ------------------- | ------------------------- | 4485| Promise<void> | Promise that returns no value.| 4486 4487**Error codes** 4488 4489For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4490 4491| ID| Error Message| 4492| ------- | -------------------------------------------- | 4493| 1300002 | This window state is abnormal. | 4494| 1300003 | This window manager service works abnormally. | 4495 4496**Example** 4497 4498```ts 4499import { BusinessError } from '@ohos.base'; 4500 4501let isTouchable: boolean = true; 4502try { 4503 let promise = windowClass.setWindowTouchable(isTouchable); 4504 promise.then(() => { 4505 console.info('Succeeded in setting the window to be touchable.'); 4506 }).catch((err: BusinessError) => { 4507 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 4508 }); 4509} catch (exception) { 4510 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 4511} 4512``` 4513 4514### setForbidSplitMove<sup>9+</sup> 4515 4516setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void 4517 4518Sets whether this window is forbidden to move in split-screen mode. This API uses an asynchronous callback to return the result. 4519 4520**System API**: This is a system API. 4521 4522**System capability**: SystemCapability.WindowManager.WindowManager.Core 4523 4524**Parameters** 4525 4526| Name | Type | Mandatory| Description | 4527| ----------- | ------------------------- | ---- | -------------------- | 4528| isForbidSplitMove | boolean | Yes | Whether the window is forbidden to move in split-screen mode. The value **true** means the window is forbidden to move in split-screen mode, and **false** means the opposite.| 4529| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4530 4531**Error codes** 4532 4533For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4534 4535| ID| Error Message| 4536| ------- | -------------------------------------------- | 4537| 1300002 | This window state is abnormal. | 4538| 1300003 | This window manager service works abnormally. | 4539 4540**Example** 4541 4542```ts 4543import { BusinessError } from '@ohos.base'; 4544 4545let isForbidSplitMove: boolean = true; 4546try { 4547 windowClass.setForbidSplitMove(isForbidSplitMove, (err: BusinessError) => { 4548 const errCode: number = err.code; 4549 if (errCode) { 4550 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(err)); 4551 return; 4552 } 4553 console.info('Succeeded in forbidding window moving in split screen mode.'); 4554 }); 4555} catch (exception) { 4556 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception)); 4557} 4558``` 4559 4560### setForbidSplitMove<sup>9+</sup> 4561 4562setForbidSplitMove(isForbidSplitMove: boolean): Promise<void> 4563 4564Sets whether this window is forbidden to move in split-screen mode. This API uses a promise to return the result. 4565 4566**System API**: This is a system API. 4567 4568**System capability**: SystemCapability.WindowManager.WindowManager.Core 4569 4570**Parameters** 4571 4572| Name | Type | Mandatory| Description | 4573| ----------- | ------- | ---- | -------------------- | 4574| isForbidSplitMove | boolean | Yes | Whether the window is forbidden to move in split-screen mode. The value **true** means the window is forbidden to move in split-screen mode, and **false** means the opposite.| 4575 4576**Return value** 4577 4578| Type | Description | 4579| ------------------- | ------------------------- | 4580| Promise<void> | Promise that returns no value.| 4581 4582**Error codes** 4583 4584For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4585 4586| ID| Error Message| 4587| ------- | -------------------------------------------- | 4588| 1300002 | This window state is abnormal. | 4589| 1300003 | This window manager service works abnormally. | 4590 4591**Example** 4592 4593```ts 4594import { BusinessError } from '@ohos.base'; 4595 4596let isForbidSplitMove: boolean = true; 4597try { 4598 let promise = windowClass.setForbidSplitMove(isForbidSplitMove); 4599 promise.then(() => { 4600 console.info('Succeeded in forbidding window moving in split screen mode.'); 4601 }).catch((err: BusinessError) => { 4602 console.error('Failed to forbid window moving in split screen mode. Cause: ' + JSON.stringify(err)); 4603 }); 4604} catch (exception) { 4605 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception)); 4606} 4607``` 4608 4609### snapshot<sup>9+</sup> 4610 4611snapshot(callback: AsyncCallback<image.PixelMap>): void 4612 4613Captures this window. This API uses an asynchronous callback to return the result. 4614 4615**System capability**: SystemCapability.WindowManager.WindowManager.Core 4616 4617**Parameters** 4618 4619| Name | Type | Mandatory | Description | 4620| -------- | ------------------------------------------------------------ | --------- | ----------------------------------- | 4621| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback used to return the result. | 4622 4623**Error codes** 4624 4625For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4626 4627| ID | Error Message | 4628| ------- | ------------------------------ | 4629| 1300002 | This window state is abnormal. | 4630 4631**Example** 4632 4633```ts 4634import { BusinessError } from '@ohos.base'; 4635import image from '@ohos.multimedia.image'; 4636 4637windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 4638 const errCode: number = err.code; 4639 if (errCode) { 4640 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 4641 return; 4642 } 4643 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 4644 pixelMap.release(); // Release the memory in time after the PixelMap is used. 4645}); 4646``` 4647 4648### snapshot<sup>9+</sup> 4649 4650snapshot(): Promise<image.PixelMap> 4651 4652Captures this window. This API uses a promise to return the result. 4653 4654**System capability**: SystemCapability.WindowManager.WindowManager.Core 4655 4656**Return value** 4657 4658| Type | Description | 4659| ----------------------------------------------------------- | --------------------------------------------- | 4660| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the window screenshot. | 4661 4662**Error codes** 4663 4664For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4665 4666| ID | Error Message | 4667| ------- | ------------------------------ | 4668| 1300002 | This window state is abnormal. | 4669 4670**Example** 4671 4672```ts 4673import { BusinessError } from '@ohos.base'; 4674import image from '@ohos.multimedia.image'; 4675 4676let promise = windowClass.snapshot(); 4677promise.then((pixelMap: image.PixelMap) => { 4678 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 4679 pixelMap.release(); // Release the memory in time after the PixelMap is used. 4680}).catch((err: BusinessError) => { 4681 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 4682}); 4683``` 4684 4685### opacity<sup>9+</sup> 4686 4687opacity(opacity: number): void 4688 4689Sets the opacity for this window. This API can be used only when you [customize an animation to be played during the display or hiding of a system window](../../windowmanager/system-window-stage.md#customizing-an-animation-to-be-played-during-the-display-or-hiding-of-a-system-window). 4690 4691**System API**: This is a system API. 4692 4693**System capability**: SystemCapability.WindowManager.WindowManager.Core 4694 4695**Parameters** 4696 4697| Name | Type | Mandatory | Description | 4698| ------- | ------ | --------- | ------------------------------------------------------------ | 4699| opacity | number | Yes | Opacity. The value is a floating point number in the range [0.0, 1.0]. The value **0.0** means completely transparent, and **1.0** means completely opaque. | 4700 4701**Error codes** 4702 4703For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4704 4705| ID | Error Message | 4706| ------- | ------------------------------ | 4707| 1300002 | This window state is abnormal. | 4708| 1300004 | Unauthorized operation. | 4709 4710**Example** 4711 4712```ts 4713try { 4714 windowClass.opacity(0.5); 4715} catch (exception) { 4716 console.error('Failed to opacity. Cause: ' + JSON.stringify(exception)); 4717} 4718``` 4719 4720### scale<sup>9+</sup> 4721 4722scale(scaleOptions: ScaleOptions): void 4723 4724Sets the scale parameters for this window. This API can be used only when you [customize an animation to be played during the display or hiding of a system window](../../windowmanager/system-window-stage.md#customizing-an-animation-to-be-played-during-the-display-or-hiding-of-a-system-window). 4725 4726**System API**: This is a system API. 4727 4728**System capability**: SystemCapability.WindowManager.WindowManager.Core 4729 4730**Parameters** 4731 4732| Name | Type | Mandatory | Description | 4733| ------------ | ------------------------------ | --------- | ------------------------ | 4734| scaleOptions | [ScaleOptions](#scaleoptions9) | Yes | Scale parameters to set. | 4735 4736**Error codes** 4737 4738For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4739 4740| ID | Error Message | 4741| ------- | ------------------------------ | 4742| 1300002 | This window state is abnormal. | 4743| 1300004 | Unauthorized operation. | 4744 4745**Example** 4746 4747```ts 4748let obj: window.ScaleOptions = { 4749 x: 2.0, 4750 y: 1.0, 4751 pivotX: 0.5, 4752 pivotY: 0.5 4753}; 4754try { 4755 windowClass.scale(obj); 4756} catch (exception) { 4757 console.error('Failed to scale. Cause: ' + JSON.stringify(exception)); 4758} 4759``` 4760 4761### rotate<sup>9+</sup> 4762 4763rotate(rotateOptions: RotateOptions): void 4764 4765Sets the rotation parameters for this window. This API can be used only when you [customize an animation to be played during the display or hiding of a system window](../../windowmanager/system-window-stage.md#customizing-an-animation-to-be-played-during-the-display-or-hiding-of-a-system-window). 4766 4767**System API**: This is a system API. 4768 4769**System capability**: SystemCapability.WindowManager.WindowManager.Core 4770 4771**Parameters** 4772 4773| Name | Type | Mandatory | Description | 4774| ------------- | -------------------------------- | --------- | --------------------------- | 4775| rotateOptions | [RotateOptions](#rotateoptions9) | Yes | Rotation parameters to set. | 4776 4777**Error codes** 4778 4779For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4780 4781| ID | Error Message | 4782| ------- | ------------------------------ | 4783| 1300002 | This window state is abnormal. | 4784| 1300004 | Unauthorized operation. | 4785 4786**Example** 4787 4788```ts 4789let obj: window.RotateOptions = { 4790 x: 1.0, 4791 y: 1.0, 4792 z: 45.0, 4793 pivotX: 0.5, 4794 pivotY: 0.5 4795}; 4796try { 4797 windowClass.rotate(obj); 4798} catch (exception) { 4799 console.error('Failed to rotate. Cause: ' + JSON.stringify(exception)); 4800} 4801``` 4802 4803### translate<sup>9+</sup> 4804 4805translate(translateOptions: TranslateOptions): void 4806 4807Sets the translation parameters for this window. This API can be used only when you [customize an animation to be played during the display or hiding of a system window](../../windowmanager/system-window-stage.md#customizing-an-animation-to-be-played-during-the-display-or-hiding-of-a-system-window). 4808 4809**System API**: This is a system API. 4810 4811**System capability**: SystemCapability.WindowManager.WindowManager.Core 4812 4813**Parameters** 4814 4815| Name | Type | Mandatory | Description | 4816| ---------------- | -------------------------------------- | --------- | ------------------------------------------- | 4817| translateOptions | [TranslateOptions](#translateoptions9) | Yes | Translation parameters. The unit is pixels. | 4818 4819**Error codes** 4820 4821For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4822 4823| ID | Error Message | 4824| ------- | ------------------------------ | 4825| 1300002 | This window state is abnormal. | 4826| 1300004 | Unauthorized operation. | 4827 4828**Example** 4829 4830```ts 4831let obj: window.TranslateOptions = { 4832 x: 100.0, 4833 y: 0.0, 4834 z: 0.0 4835}; 4836try { 4837 windowClass.translate(obj); 4838} catch (exception) { 4839 console.error('Failed to translate. Cause: ' + JSON.stringify(exception)); 4840} 4841``` 4842 4843### getTransitionController<sup>9+</sup> 4844 4845 getTransitionController(): TransitionController 4846 4847Obtains the transition animation controller. 4848 4849**System API**: This is a system API. 4850 4851**System capability**: SystemCapability.WindowManager.WindowManager.Core 4852 4853**Return value** 4854 4855| Type | Description | 4856| ---------------------------------------------- | -------------------------------- | 4857| [TransitionController](#transitioncontroller9) | Transition animation controller. | 4858 4859**Error codes** 4860 4861For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4862 4863| ID | Error Message | 4864| ------- | ------------------------------ | 4865| 1300002 | This window state is abnormal. | 4866| 1300004 | Unauthorized operation. | 4867 4868**Example** 4869 4870```ts 4871import { BusinessError } from '@ohos.base'; 4872 4873let controller = windowClass.getTransitionController(); // Obtain the transition animation controller. 4874controller.animationForHidden = (context: window.TransitionContext) => { 4875 let toWindow = context.toWindow; 4876 animateTo({ 4877 duration: 1000, // Animation duration. 4878 tempo: 0.5, // Playback speed. 4879 curve: Curve.EaseInOut, // Animation curve. 4880 delay: 0, // Animation delay. 4881 iterations: 1, // Number of playback times. 4882 playMode: PlayMode.Normal // Animation playback mode. 4883 onFinish: () => { 4884 context.completeTransition(true) 4885 } 4886 }, () => { 4887 let obj: window.TranslateOptions = { 4888 x: 100.0, 4889 y: 0.0, 4890 z: 0.0 4891 }; 4892 toWindow.translate(obj); // Set the transition animation. 4893 console.info('toWindow translate end'); 4894 } 4895 ); 4896 console.info('complete transition end'); 4897}; 4898windowClass.hideWithAnimation((err: BusinessError, data) => { 4899 const errCode: number = err.code; 4900 if (errCode) { 4901 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 4902 return; 4903 } 4904 console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); 4905}); 4906``` 4907 4908### setBlur<sup>9+</sup> 4909 4910setBlur(radius: number): void 4911 4912Blurs this window. 4913 4914**System API**: This is a system API. 4915 4916**System capability**: SystemCapability.WindowManager.WindowManager.Core 4917 4918**Parameters** 4919 4920| Name | Type | Mandatory | Description | 4921| ------ | ------ | --------- | ------------------------------------------------------------ | 4922| radius | number | Yes | Radius of the blur. The value is a floating point number greater than or equal to 0.0, and the value **0.0** means that the blur is disabled for the window. | 4923 4924**Error codes** 4925 4926For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4927 4928| ID | Error Message | 4929| ------- | ------------------------------ | 4930| 1300002 | This window state is abnormal. | 4931| 1300004 | Unauthorized operation. | 4932 4933**Example** 4934 4935```ts 4936try { 4937 windowClass.setBlur(4.0); 4938} catch (exception) { 4939 console.error('Failed to set blur. Cause: ' + JSON.stringify(exception)); 4940} 4941``` 4942 4943### setBackdropBlur<sup>9+</sup> 4944 4945setBackdropBlur(radius: number): void 4946 4947Blurs the background of this window. 4948 4949**System API**: This is a system API. 4950 4951**System capability**: SystemCapability.WindowManager.WindowManager.Core 4952 4953**Parameters** 4954 4955| Name | Type | Mandatory | Description | 4956| ------ | ------ | --------- | ------------------------------------------------------------ | 4957| radius | number | Yes | Radius of the blur. The value is a floating point number greater than or equal to 0.0, and the value **0.0** means that the blur is disabled for the background of the window. | 4958 4959**Error codes** 4960 4961For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4962 4963| ID | Error Message | 4964| ------- | ------------------------------ | 4965| 1300002 | This window state is abnormal. | 4966| 1300004 | Unauthorized operation. | 4967 4968**Example** 4969 4970```ts 4971try { 4972 windowClass.setBackdropBlur(4.0); 4973} catch (exception) { 4974 console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception)); 4975} 4976``` 4977 4978### setBackdropBlurStyle<sup>9+</sup> 4979 4980setBackdropBlurStyle(blurStyle: BlurStyle): void 4981 4982Sets the blur style for the background of this window. 4983 4984**System API**: This is a system API. 4985 4986**System capability**: SystemCapability.WindowManager.WindowManager.Core 4987 4988**Parameters** 4989 4990| Name | Type | Mandatory | Description | 4991| --------- | ------------------------ | --------- | --------------------------------------------------- | 4992| blurStyle | [BlurStyle](#blurstyle9) | Yes | Blur style to set for the background of the window. | 4993 4994**Error codes** 4995 4996For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 4997 4998| ID | Error Message | 4999| ------- | ------------------------------ | 5000| 1300002 | This window state is abnormal. | 5001| 1300004 | Unauthorized operation. | 5002 5003**Example** 5004 5005```ts 5006try { 5007 windowClass.setBackdropBlurStyle(window.BlurStyle.THIN); 5008} catch (exception) { 5009 console.error('Failed to set backdrop blur style. Cause: ' + JSON.stringify(exception)); 5010} 5011``` 5012 5013### setShadow<sup>9+</sup> 5014 5015setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void 5016 5017Sets the shadow for the window borders. 5018 5019**System API**: This is a system API. 5020 5021**System capability**: SystemCapability.WindowManager.WindowManager.Core 5022 5023**Parameters** 5024 5025| Name | Type | Mandatory | Description | 5026| ------- | ------ | --------- | ------------------------------------------------------------ | 5027| radius | number | Yes | Radius of the shadow. The value is a floating point number greater than or equal to 0.0, and the value **0.0** means that the shadow is disabled for the window borders. | 5028| color | string | No | Color of the shadow. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**. | 5029| offsetX | number | No | Offset of the shadow along the x-axis, in pixels. The value is a floating point number. | 5030| offsetY | number | No | Offset of the shadow along the y-axis, in pixels. The value is a floating point number. | 5031 5032**Error codes** 5033 5034For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5035 5036| ID | Error Message | 5037| ------- | ------------------------------ | 5038| 1300002 | This window state is abnormal. | 5039| 1300004 | Unauthorized operation. | 5040 5041**Example** 5042 5043```ts 5044try { 5045 windowClass.setShadow(4.0, '#FF00FF00', 2, 3); 5046} catch (exception) { 5047 console.error('Failed to set shadow. Cause: ' + JSON.stringify(exception)); 5048} 5049``` 5050 5051### setCornerRadius<sup>9+</sup> 5052 5053setCornerRadius(cornerRadius: number): void 5054 5055Sets the radius of the rounded corners for this window. 5056 5057**System API**: This is a system API. 5058 5059**System capability**: SystemCapability.WindowManager.WindowManager.Core 5060 5061**Parameters** 5062 5063| Name | Type | Mandatory | Description | 5064| ------ | ------ | --------- | ------------------------------------------------------------ | 5065| radius | number | Yes | Radius of the rounded corners. The value is a floating point number greater than or equal to 0.0. The value **0.0** means that the window does not use rounded corners. | 5066 5067**Error codes** 5068 5069For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5070 5071| ID | Error Message | 5072| ------- | ------------------------------ | 5073| 1300002 | This window state is abnormal. | 5074| 1300004 | Unauthorized operation. | 5075 5076**Example** 5077 5078```ts 5079try { 5080 windowClass.setCornerRadius(4.0); 5081} catch (exception) { 5082 console.error('Failed to set corner radius. Cause: ' + JSON.stringify(exception)); 5083} 5084``` 5085 5086### raiseToAppTop<sup>10+</sup> 5087 5088raiseToAppTop(callback: AsyncCallback<void>): void 5089 5090Raises the application subwindow to the top layer of the application. This API uses an asynchronous callback to return the result. 5091 5092**System API**: This is a system API. 5093 5094**System capability**: SystemCapability.WindowManager.WindowManager.Core 5095 5096**Parameters** 5097 5098| Name | Type | Mandatory | Description | 5099| -------- | ------------------------- | --------- | ----------------------------------- | 5100| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5101 5102**Error codes** 5103 5104For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5105 5106| ID | Error Message | 5107| ------- | --------------------------------------------- | 5108| 1300002 | This window state is abnormal. | 5109| 1300003 | This window manager service works abnormally. | 5110| 1300004 | Unauthorized operation. | 5111| 1300009 | The parent window is invalid. | 5112 5113**Example** 5114 5115```ts 5116import { BusinessError } from '@ohos.base'; 5117 5118windowClass.raiseToAppTop((err: BusinessError) => { 5119 const errCode: number = err.code; 5120 if (errCode) { 5121 console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err)); 5122 return; 5123 } 5124 console.info('Succeeded in raising the window to app top.'); 5125}); 5126``` 5127 5128### raiseToAppTop<sup>10+</sup> 5129 5130raiseToAppTop(): Promise<void> 5131 5132Raises the application subwindow to the top layer of the application. This API uses a promise to return the result. 5133 5134**System API**: This is a system API. 5135 5136**System capability**: SystemCapability.WindowManager.WindowManager.Core 5137 5138**Return value** 5139 5140| Type | Description | 5141| ------------------- | ------------------------------ | 5142| Promise<void> | Promise that returns no value. | 5143 5144**Error codes** 5145 5146For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5147 5148| ID | Error Message | 5149| ------- | --------------------------------------------- | 5150| 1300002 | This window state is abnormal. | 5151| 1300003 | This window manager service works abnormally. | 5152| 1300004 | Unauthorized operation. | 5153| 1300009 | The parent window is invalid. | 5154 5155**Example** 5156 5157```ts 5158import { BusinessError } from '@ohos.base'; 5159 5160let promise = windowClass.raiseToAppTop(); 5161promise.then(() => { 5162 console.info('Succeeded in raising the window to app top.'); 5163}).catch((err: BusinessError) => { 5164 console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err)); 5165}); 5166``` 5167### setAspectRatio<sup>10+</sup> 5168 5169setAspectRatio(ratio: number): Promise<void> 5170 5171Sets the aspect ratio of the window content layout. This API uses a promise to return the result. 5172 5173This API is available only for the main window of the application. The aspect ratio will be saved permanently and takes effect even after the application is closed or the device is restarted. 5174 5175**System capability**: SystemCapability.WindowManager.WindowManager.Core 5176 5177**Parameters** 5178 5179| Name | Type | Mandatory | Description | 5180| ----- | ------ | --------- | ------------------------------------------------------------ | 5181| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating point number greater than or equal to 0.0. | 5182 5183**Return value** 5184 5185| Type | Description | 5186| ------------------- | ------------------------------ | 5187| Promise<void> | Promise that returns no value. | 5188 5189**Error codes** 5190 5191For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5192 5193| ID | Error Message | 5194| ------- | ------------------------------ | 5195| 1300002 | This window state is abnormal. | 5196| 1300004 | Unauthorized operation. | 5197 5198**Example** 5199 5200```ts 5201import { BusinessError } from '@ohos.base'; 5202 5203try { 5204 let ratio = 1.0; 5205 let promise = windowClass.setAspectRatio(ratio); 5206 promise.then(() => { 5207 console.info('Succeeded in setting aspect ratio of window.'); 5208 }).catch((err: BusinessError) => { 5209 console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err)); 5210 }); 5211} catch (exception) { 5212 console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5213} 5214``` 5215 5216### setAspectRatio<sup>10+</sup> 5217 5218setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 5219 5220Sets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 5221 5222This API is available only for the main window of the application. The aspect ratio will be saved permanently and takes effect even after the application is closed or the device is restarted. 5223 5224**System capability**: SystemCapability.WindowManager.WindowManager.Core 5225 5226**Parameters** 5227 5228| Name | Type | Mandatory | Description | 5229| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 5230| ratio | number | Yes | Aspect ratio of the window content layout except border decoration. The value is a floating point number greater than or equal to 0.0. | 5231| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5232 5233**Error codes** 5234 5235For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5236 5237| ID | Error Message | 5238| ------- | ------------------------------ | 5239| 1300002 | This window state is abnormal. | 5240| 1300004 | Unauthorized operation. | 5241 5242**Example** 5243 5244```ts 5245import { BusinessError } from '@ohos.base'; 5246 5247try { 5248 let ratio = 1.0; 5249 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 5250 const errCode: number = err.code; 5251 if (errCode) { 5252 console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err)); 5253 return; 5254 } 5255 console.info('Succeeded in setting the aspect ratio of window.'); 5256 }); 5257} catch (exception) { 5258 console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5259} 5260``` 5261 5262### resetAspectRatio<sup>10+</sup> 5263 5264resetAspectRatio(): Promise<void> 5265 5266Resets the aspect ratio of the window content layout. This API uses a promise to return the result. 5267 5268This API is available only for the main window of the application. After this API is called, the persistently stored aspect ratio is cleared. 5269 5270**System capability**: SystemCapability.WindowManager.WindowManager.Core 5271 5272**Return value** 5273 5274| Type | Description | 5275| ------------------- | ------------------------------ | 5276| Promise<void> | Promise that returns no value. | 5277 5278**Error codes** 5279 5280For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5281 5282| ID | Error Message | 5283| ------- | ------------------------------ | 5284| 1300002 | This window state is abnormal. | 5285| 1300004 | Unauthorized operation. | 5286 5287**Example** 5288 5289```ts 5290import { BusinessError } from '@ohos.base'; 5291 5292try { 5293 let promise = windowClass.resetAspectRatio(); 5294 promise.then(() => { 5295 console.info('Succeeded in resetting aspect ratio of window.'); 5296 }).catch((err: BusinessError) => { 5297 console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err)); 5298 }); 5299} catch (exception) { 5300 console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5301} 5302``` 5303 5304### resetAspectRatio<sup>10+</sup> 5305 5306resetAspectRatio(callback: AsyncCallback<void>): void 5307 5308Resets the aspect ratio of the window content layout. This API uses an asynchronous callback to return the result. 5309 5310This API is available only for the main window of the application. After this API is called, the persistently stored aspect ratio is cleared. 5311 5312**System capability**: SystemCapability.WindowManager.WindowManager.Core 5313 5314**Parameters** 5315 5316| Name | Type | Mandatory | Description | 5317| -------- | ------------------------- | --------- | ----------------------------------- | 5318| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5319 5320**Error codes** 5321 5322For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5323 5324| ID | Error Message | 5325| ------- | ------------------------------ | 5326| 1300002 | This window state is abnormal. | 5327| 1300004 | Unauthorized operation. | 5328 5329**Example** 5330 5331```ts 5332import { BusinessError } from '@ohos.base'; 5333 5334try { 5335 windowClass.resetAspectRatio((err: BusinessError) => { 5336 const errCode: number = err.code; 5337 if (errCode) { 5338 console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err)); 5339 return; 5340 } 5341 console.info('Succeeded in resetting aspect ratio of window.'); 5342 }); 5343} catch (exception) { 5344 console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5345} 5346``` 5347 5348### setWaterMarkFlag<sup>10+</sup> 5349 5350setWaterMarkFlag(enable: boolean): Promise<void> 5351 5352Adds or deletes the watermark flag for this window. This API uses a promise to return the result. 5353 5354**System API**: This is a system API. 5355 5356**System capability**: SystemCapability.WindowManager.WindowManager.Core 5357 5358**Parameters** 5359 5360| Name | Type | Mandatory | Description | 5361| ------ | ------- | --------- | ------------------------------------------------------------ | 5362| enable | boolean | Yes | Whether to add or delete the watermark flag to the window. The value **true** means to add the watermark flag and **false** means to delete the watermark flag. | 5363 5364**Return value** 5365 5366| Type | Description | 5367| ------------------- | ------------------------------ | 5368| Promise<void> | Promise that returns no value. | 5369 5370**Error codes** 5371 5372For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5373 5374| ID | Error Message | 5375| ------- | --------------------------------------------- | 5376| 1300002 | This window state is abnormal. | 5377| 1300003 | This window manager service works abnormally. | 5378| 1300008 | The operation is on invalid display. | 5379 5380**Example** 5381 5382```ts 5383import { BusinessError } from '@ohos.base'; 5384 5385try { 5386 let enable = true; 5387 let promise = windowClass.setWaterMarkFlag(enable); 5388 promise.then(() => { 5389 console.info('Succeeded in setting water mark flag of window.'); 5390 }).catch((err: BusinessError) => { 5391 console.error('Failed to set water mark flag of window. Cause:' + JSON.stringify(err)); 5392 }); 5393} catch (exception) { 5394 console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception)); 5395} 5396``` 5397 5398### setWaterMarkFlag<sup>10+</sup> 5399 5400setWaterMarkFlag(enable: boolean, callback: AsyncCallback<void>): void 5401 5402Adds or deletes the watermark flag for this window. This API uses an asynchronous callback to return the result. 5403 5404**System API**: This is a system API. 5405 5406**System capability**: SystemCapability.WindowManager.WindowManager.Core 5407 5408**Parameters** 5409 5410| Name | Type | Mandatory | Description | 5411| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 5412| enable | boolean | Yes | Whether to add or delete the watermark flag to the window. The value **true** means to add the watermark flag and **false** means to delete the watermark flag. | 5413| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5414 5415**Error codes** 5416 5417For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5418 5419| ID | Error Message | 5420| ------- | --------------------------------------------- | 5421| 1300002 | This window state is abnormal. | 5422| 1300003 | This window manager service works abnormally. | 5423| 1300008 | The operation is on invalid display. | 5424 5425**Example** 5426 5427```ts 5428import { BusinessError } from '@ohos.base'; 5429 5430try { 5431 let enable: boolean = true; 5432 windowClass.setWaterMarkFlag(enable, (err: BusinessError) => { 5433 const errCode: number = err.code; 5434 if (errCode) { 5435 console.error('Failed to set water mark flag of window. Cause:' + JSON.stringify(err)); 5436 return; 5437 } 5438 console.info('Succeeded in setting water mark flag of window.'); 5439 }); 5440} catch (exception) { 5441 console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception)); 5442} 5443``` 5444### raiseAboveTarget<sup>10+</sup> 5445 5446raiseAboveTarget(windowId: number, callback: AsyncCallback<void>): void 5447 5448Raises a subwindow above a target subwindow. This API uses an asynchronous callback to return the result. 5449 5450**System API**: This is a system API. 5451 5452**System capability**: SystemCapability.Window.SessionManager 5453 5454**Parameters** 5455 5456| Name | Type | Mandatory | Description | 5457| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 5458| windowId | number | Yes | ID of the target subwindow, which is the value of **properties.id** in [properties](#windowproperties) obtained through [getWindowProperties](#getwindowproperties9). | 5459| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5460 5461**Error codes** 5462 5463For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5464 5465| ID | Error Message | 5466| ------- | --------------------------------------------- | 5467| 1300002 | This window state is abnormal. | 5468| 1300003 | This window manager service works abnormally. | 5469| 1300004 | Unauthorized operation. | 5470| 1300009 | The parent window is invalid. | 5471 5472**Example** 5473 5474```ts 5475// Raise windowClass above targetWindow. 5476let properties = targetWindow.getWindowProperties(); 5477let targetId = properties.id; 5478windowClass.raiseAboveTarget(targetId, (err) => { 5479 if (err.code) { 5480 console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err)); 5481 return; 5482 } 5483 console.info('Succeeded in raising the subWindow to target subWindow top.'); 5484}); 5485``` 5486 5487### raiseAboveTarget<sup>10+</sup> 5488 5489raiseAboveTarget(windowId: number): Promise<void> 5490 5491Raises a subwindow above a target subwindow. This API uses a promise to return the result. 5492 5493**System API**: This is a system API. 5494 5495**System capability**: SystemCapability.Window.SessionManager 5496 5497**Parameters** 5498 5499| Name | Type | Mandatory | Description | 5500| -------- | ------ | --------- | ------------------------------------------------------------ | 5501| windowId | number | Yes | ID of the target subwindow, which is the value of **properties.id** in [properties](#windowproperties) obtained through [getWindowProperties](#getwindowproperties9). | 5502 5503**Return value** 5504 5505| Type | Description | 5506| ------------------- | ------------------------------ | 5507| Promise<void> | Promise that returns no value. | 5508 5509**Error codes** 5510 5511For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5512 5513| ID | Error Message | 5514| ------- | --------------------------------------------- | 5515| 1300002 | This window state is abnormal. | 5516| 1300003 | This window manager service works abnormally. | 5517| 1300004 | Unauthorized operation. | 5518| 1300009 | The parent window is invalid. | 5519 5520**Example** 5521 5522```ts 5523// Raise windowClass above targetWindow. 5524let properties = targetWindow.getWindowProperties(); 5525let targetId = properties.id; 5526let promise = windowClass.raiseAboveTarget(targetId); 5527promise.then(()=> { 5528 console.info('Succeeded in raising the subWindow to target subWindow top.'); 5529}).catch((err)=>{ 5530 console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err)); 5531}); 5532``` 5533### setRaiseByClickEnabled<sup>10+</sup> 5534 5535setRaiseByClickEnabled(enable: boolean, callback: AsyncCallback<void>): void 5536 5537Sets whether to enable a subwindow to raise itself by click. This API uses an asynchronous callback to return the result. 5538 5539Generally, when a user clicks a subwindow, the subwindow is displayed on the top. If the **enable** parameter is set to **false**, the subwindow is not displayed on the top when being clicked. 5540 5541**System API**: This is a system API. 5542 5543**System capability**: SystemCapability.Window.SessionManager 5544 5545**Parameters** 5546 5547| Name | Type | Mandatory | Description | 5548| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 5549| enable | boolean | Yes | Whether to enable a subwindow to raise itself by click. The value **true** means to enable the subwindow to raise itself by click, and **false** means the opposite. | 5550| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5551 5552**Error codes** 5553 5554For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5555 5556| ID | Error Message | 5557| ------- | --------------------------------------------- | 5558| 1300002 | This window state is abnormal. | 5559| 1300003 | This window manager service works abnormally. | 5560| 1300004 | Unauthorized operation. | 5561| 1300009 | The parent window is invalid. | 5562 5563**Example** 5564 5565```ts 5566let enabled = false; 5567windowClass.setRaiseByClickEnabled(enabled, (err) => { 5568 if (err.code) { 5569 console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err)); 5570 return; 5571 } 5572 console.info('Succeeded in disabling the raise-by-click function.'); 5573}); 5574``` 5575 5576### setRaiseByClickEnabled<sup>10+</sup> 5577 5578setRaiseByClickEnabled(enable: boolean): Promise<void> 5579 5580Sets whether to enable a subwindow to raise itself by click. This API uses a promise to return the result. 5581 5582Generally, when a user clicks a subwindow, the subwindow is displayed on the top. If the **enable** parameter is set to **false**, the subwindow is not displayed on the top when being clicked. 5583 5584**System API**: This is a system API. 5585 5586**System capability**: SystemCapability.Window.SessionManager 5587 5588**Parameters** 5589 5590| Name | Type | Mandatory | Description | 5591| ------ | ------- | --------- | ------------------------------------------------------------ | 5592| enable | boolean | Yes | Whether to enable a subwindow to raise itself by click. The value **true** means to enable the subwindow to raise itself by click, and **false** means the opposite. | 5593 5594**Return value** 5595 5596| Type | Description | 5597| ------------------- | ------------------------------ | 5598| Promise<void> | Promise that returns no value. | 5599 5600**Error codes** 5601 5602For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5603 5604| ID | Error Message | 5605| ------- | --------------------------------------------- | 5606| 1300002 | This window state is abnormal. | 5607| 1300003 | This window manager service works abnormally. | 5608| 1300004 | Unauthorized operation. | 5609| 1300009 | The parent window is invalid. | 5610 5611**Example** 5612 5613```ts 5614let enabled = false; 5615let promise = windowClass.setRaiseByClickEnabled(enabled); 5616promise.then(()=> { 5617 console.info('Succeeded in disabling the raise-by-click function.'); 5618}).catch((err)=>{ 5619 console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err)); 5620}); 5621``` 5622### minimize<sup>10+</sup> 5623 5624minimize(callback: AsyncCallback<void>): void 5625 5626Minimizes the main window. This API uses an asynchronous callback to return the result. 5627 5628**System API**: This is a system API. 5629 5630**System capability**: SystemCapability.Window.SessionManager 5631 5632**Parameters** 5633 5634| Name | Type | Mandatory | Description | 5635| -------- | ------------------------- | --------- | ----------------------------------- | 5636| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5637 5638**Error codes** 5639 5640For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5641 5642| ID | Error Message | 5643| ------- | --------------------------------------------- | 5644| 1300002 | This window state is abnormal. | 5645| 1300003 | This window manager service works abnormally. | 5646 5647**Example** 5648 5649```ts 5650import UIAbility from '@ohos.app.ability.UIAbility'; 5651 5652export default class EntryAbility extends UIAbility { 5653 onWindowStageCreate(windowStage) { 5654 // Load content for the main window. 5655 windowStage.loadContent("pages/page2", (err) => { 5656 if (err.code) { 5657 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5658 return; 5659 } 5660 console.info('Succeeded in loading the content.'); 5661 }); 5662 // Obtain the main window. 5663 let mainWindow = null; 5664 5665 windowStage.getMainWindow((err, data) => { 5666 if (err.code) { 5667 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5668 return; 5669 } 5670 mainWindow = data; 5671 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5672 // Call minimize. 5673 mainWindow.minimize((err) => { 5674 if (err.code) { 5675 console.error('Failed to minimize the app main window. Cause: ' + JSON.stringify(err)); 5676 return; 5677 } 5678 console.info('Successfully minimized app main window.'); 5679 }); 5680 }) 5681 } 5682}; 5683``` 5684 5685### minimize<sup>10+</sup> 5686 5687minimize(): Promise<void> 5688 5689Minimizes the main window. This API uses a promise to return the result. 5690 5691**System API**: This is a system API. 5692 5693**System capability**: SystemCapability.Window.SessionManager 5694 5695**Return value** 5696 5697| Type | Description | 5698| ------------------- | ------------------------------ | 5699| Promise<void> | Promise that returns no value. | 5700 5701**Error codes** 5702 5703For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5704 5705| ID | Error Message | 5706| ------- | --------------------------------------------- | 5707| 1300002 | This window state is abnormal. | 5708| 1300003 | This window manager service works abnormally. | 5709 5710**Example** 5711 5712```ts 5713import UIAbility from '@ohos.app.ability.UIAbility'; 5714 5715export default class EntryAbility extends UIAbility { 5716 onWindowStageCreate(windowStage) { 5717 // Load content for the main window. 5718 windowStage.loadContent("pages/page2", (err) => { 5719 if (err.code) { 5720 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5721 return; 5722 } 5723 console.info('Succeeded in loading the content.'); 5724 }); 5725 // Obtain the main window. 5726 let mainWindow = null; 5727 5728 windowStage.getMainWindow((err, data) => { 5729 if (err.code) { 5730 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5731 return; 5732 } 5733 mainWindow = data; 5734 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5735 // Promise object of the minimize API. 5736 let promise = mainWindow.minimize(); 5737 promise.then(()=> { 5738 console.info('Successfully minimized app main window.'); 5739 }).catch((err)=>{ 5740 console.error('Failed to minimize the app main window. Cause: ' + JSON.stringify(err)); 5741 }); 5742 }) 5743 } 5744}; 5745``` 5746 5747### setResizeByDragEnabled<sup>10+</sup> 5748 5749setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 5750 5751Sets whether to enable the main window to resize itself by dragging. This API uses an asynchronous callback to return the result. 5752 5753**System API**: This is a system API. 5754 5755**System capability**: SystemCapability.Window.SessionManager 5756 5757**Parameters** 5758 5759| Name | Type | Mandatory | Description | 5760| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 5761| enable | boolean | Yes | Whether to enable the main window to resize itself by dragging. The value **true** means to enable the main window to resize itself by dragging, and **false** means the opposite. | 5762| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5763 5764**Error codes** 5765 5766For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5767 5768| ID | Error Message | 5769| ------- | --------------------------------------------- | 5770| 1300002 | This window state is abnormal. | 5771| 1300003 | This window manager service works abnormally. | 5772| 1300004 | Unauthorized operation. | 5773 5774**Example** 5775 5776```ts 5777import UIAbility from '@ohos.app.ability.UIAbility'; 5778 5779export default class EntryAbility extends UIAbility { 5780 onWindowStageCreate(windowStage) { 5781 // Load content for the main window. 5782 windowStage.loadContent("pages/page2", (err) => { 5783 if (err.code) { 5784 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5785 return; 5786 } 5787 console.info('Succeeded in loading the content.'); 5788 }); 5789 // Obtain the main window. 5790 let mainWindow = null; 5791 5792 windowStage.getMainWindow((err, data) => { 5793 if (err.code) { 5794 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5795 return; 5796 } 5797 mainWindow = data; 5798 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5799 5800 let enabled = false; 5801 // Call setResizeByDragEnabled. 5802 mainWindow.setResizeByDragEnabled(enabled, (err) => { 5803 if (err.code) { 5804 console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err)); 5805 return; 5806 } 5807 console.info('Succeeded in setting the function of disabling the resize by dragg window.'); 5808 }); 5809 }) 5810 } 5811}; 5812``` 5813 5814### setResizeByDragEnabled<sup>10+</sup> 5815 5816setResizeByDragEnabled(enable: boolean): Promise<void> 5817 5818Sets whether to enable the main window to resize itself by dragging. This API uses a promise to return the result. 5819 5820**System API**: This is a system API. 5821 5822**System capability**: SystemCapability.Window.SessionManager 5823 5824**Parameters** 5825 5826| Name | Type | Mandatory | Description | 5827| ------ | ------- | --------- | ------------------------------------------------------------ | 5828| enable | boolean | Yes | Whether to enable the main window to resize itself by dragging. The value **true** means to enable the main window to resize itself by dragging, and **false** means the opposite. | 5829 5830**Return value** 5831 5832| Type | Description | 5833| ------------------- | ------------------------------ | 5834| Promise<void> | Promise that returns no value. | 5835 5836**Error codes** 5837 5838For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 5839 5840| ID | Error Message | 5841| ------- | --------------------------------------------- | 5842| 1300002 | This window state is abnormal. | 5843| 1300003 | This window manager service works abnormally. | 5844 5845**Example** 5846 5847```ts 5848import UIAbility from '@ohos.app.ability.UIAbility'; 5849 5850export default class EntryAbility extends UIAbility { 5851 onWindowStageCreate(windowStage) { 5852 // Load content for the main window. 5853 windowStage.loadContent("pages/page2", (err) => { 5854 if (err.code) { 5855 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5856 return; 5857 } 5858 console.info('Succeeded in loading the content.'); 5859 }); 5860 // Obtain the main window. 5861 let mainWindow = null; 5862 5863 windowStage.getMainWindow((err, data) => { 5864 if (err.code) { 5865 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5866 return; 5867 } 5868 mainWindow = data; 5869 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5870 5871 let enabled = false; 5872 // Promise object of the setResizeByDragEnabled API. 5873 let promise = mainWindow.setResizeByDragEnabled(enabled); 5874 promise.then(()=> { 5875 console.info('Succeeded in setting the function of disabling the resize by dragg window.'); 5876 }).catch((err)=>{ 5877 console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err)); 5878 }); 5879 }) 5880 } 5881}; 5882``` 5883 5884### show<sup>(deprecated)</sup> 5885 5886show(callback: AsyncCallback<void>): void 5887 5888Shows this window. This API uses an asynchronous callback to return the result. 5889 5890> **NOTE** 5891> 5892> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9) instead. 5893 5894**System capability**: SystemCapability.WindowManager.WindowManager.Core 5895 5896**Parameters** 5897 5898| Name | Type | Mandatory | Description | 5899| -------- | ------------------------- | --------- | ----------------------------------- | 5900| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5901 5902**Example** 5903 5904```ts 5905import { BusinessError } from '@ohos.base'; 5906 5907windowClass.show((err: BusinessError) => { 5908 const errCode: number = err.code; 5909 if (errCode) { 5910 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 5911 return; 5912 } 5913 console.info('Succeeded in showing the window.'); 5914}); 5915``` 5916 5917### show<sup>(deprecated)</sup> 5918 5919show(): Promise<void> 5920 5921Shows this window. This API uses a promise to return the result. 5922 5923> **NOTE** 5924> 5925> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [showWindow()](#showwindow9-1) instead. 5926 5927**System capability**: SystemCapability.WindowManager.WindowManager.Core 5928 5929**Return value** 5930 5931| Type | Description | 5932| ------------------- | ------------------------------ | 5933| Promise<void> | Promise that returns no value. | 5934 5935**Example** 5936 5937```ts 5938import { BusinessError } from '@ohos.base'; 5939 5940let promise = windowClass.show(); 5941promise.then(() => { 5942 console.info('Succeeded in showing the window.'); 5943}).catch((err: BusinessError) => { 5944 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 5945}); 5946``` 5947 5948### destroy<sup>(deprecated)</sup> 5949 5950destroy(callback: AsyncCallback<void>): void 5951 5952Destroys this window. This API uses an asynchronous callback to return the result. 5953 5954> **NOTE** 5955> 5956> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9) instead. 5957 5958**System capability**: SystemCapability.WindowManager.WindowManager.Core 5959 5960**Parameters** 5961 5962| Name | Type | Mandatory | Description | 5963| -------- | ------------------------- | --------- | ----------------------------------- | 5964| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5965 5966**Example** 5967 5968```ts 5969import { BusinessError } from '@ohos.base'; 5970 5971windowClass.destroy((err: BusinessError) => { 5972 const errCode: number = err.code; 5973 if (err.code) { 5974 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 5975 return; 5976 } 5977 console.info('Succeeded in destroying the window.'); 5978}); 5979``` 5980 5981### destroy<sup>(deprecated)</sup> 5982 5983destroy(): Promise<void> 5984 5985Destroys this window. This API uses a promise to return the result. 5986 5987> **NOTE** 5988> 5989> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [destroyWindow()](#destroywindow9-1) instead. 5990 5991**System capability**: SystemCapability.WindowManager.WindowManager.Core 5992 5993**Return value** 5994 5995| Type | Description | 5996| ------------------- | ------------------------------ | 5997| Promise<void> | Promise that returns no value. | 5998 5999**Example** 6000 6001```ts 6002import { BusinessError } from '@ohos.base'; 6003 6004let promise = windowClass.destroy(); 6005promise.then(() => { 6006 console.info('Succeeded in destroying the window.'); 6007}).catch((err: BusinessError) => { 6008 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 6009}); 6010``` 6011 6012### moveTo<sup>(deprecated)</sup> 6013 6014moveTo(x: number, y: number, callback: AsyncCallback<void>): void 6015 6016Moves this window. This API uses an asynchronous callback to return the result. 6017 6018This operation is not supported in a window in full-screen mode. 6019 6020> **NOTE** 6021> 6022> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9) instead. 6023 6024**System capability**: SystemCapability.WindowManager.WindowManager.Core 6025 6026**Parameters** 6027 6028| Name | Type | Mandatory | Description | 6029| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 6030| 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. The value must be an integer. | 6031| y | number | Yes | Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards. The value must be an integer. | 6032| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6033 6034**Example** 6035 6036```ts 6037import { BusinessError } from '@ohos.base'; 6038 6039windowClass.moveTo(300, 300, (err: BusinessError) => { 6040 const errCode: number = err.code; 6041 if (errCode) { 6042 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 6043 return; 6044 } 6045 console.info('Succeeded in moving the window.'); 6046}); 6047``` 6048 6049### moveTo<sup>(deprecated)</sup> 6050 6051moveTo(x: number, y: number): Promise<void> 6052 6053Moves this window. This API uses a promise to return the result. 6054 6055This operation is not supported in a window in full-screen mode. 6056 6057> **NOTE** 6058> 6059> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [moveWindowTo()](#movewindowto9-1) instead. 6060 6061**System capability**: SystemCapability.WindowManager.WindowManager.Core 6062 6063**Parameters** 6064 6065| Name | Type | Mandatory | Description | 6066| ---- | ------ | --------- | ------------------------------------------------------------ | 6067| 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. The value must be an integer. | 6068| y | number | Yes | Distance that the window moves along the y-axis, in px. A positive value indicates that the window moves downwards. The value must be an integer. | 6069 6070**Return value** 6071 6072| Type | Description | 6073| ------------------- | ------------------------------ | 6074| Promise<void> | Promise that returns no value. | 6075 6076**Example** 6077 6078```ts 6079import { BusinessError } from '@ohos.base'; 6080 6081let promise = windowClass.moveTo(300, 300); 6082promise.then(() => { 6083 console.info('Succeeded in moving the window.'); 6084}).catch((err: BusinessError) => { 6085 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 6086}); 6087``` 6088 6089### resetSize<sup>(deprecated)</sup> 6090 6091resetSize(width: number, height: number, callback: AsyncCallback<void>): void 6092 6093Changes the size of this window. This API uses an asynchronous callback to return the result. 6094 6095The main window and subwindow have the following size limits: [320, 2560] in width and [240, 2560] in height, both in units of vp. 6096 6097The system window has the following size limits: [0, 2560] in width and [0, 2560] in height, both in units of vp. 6098 6099The new width and height you set must meet the limits. 6100 6101This operation is not supported in a window in full-screen mode. 6102 6103> **NOTE** 6104> 6105> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9) instead. 6106 6107**System capability**: SystemCapability.WindowManager.WindowManager.Core 6108 6109**Parameters** 6110 6111| Name | Type | Mandatory | Description | 6112| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 6113| width | number | Yes | New width of the window, in px. The value must be an integer. | 6114| height | number | Yes | New height of the window, in px. The value must be an integer. | 6115| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6116 6117**Example** 6118 6119```ts 6120import { BusinessError } from '@ohos.base'; 6121 6122windowClass.resetSize(500, 1000, (err: BusinessError) => { 6123 const errCode: number = err.code; 6124 if (errCode) { 6125 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 6126 return; 6127 } 6128 console.info('Succeeded in changing the window size.'); 6129}); 6130``` 6131 6132### resetSize<sup>(deprecated)</sup> 6133 6134resetSize(width: number, height: number): Promise<void> 6135 6136Changes the size of this window. This API uses a promise to return the result. 6137 6138The main window and subwindow have the following size limits: [320, 2560] in width and [240, 2560] in height, both in units of vp. 6139 6140The system window has the following size limits: [0, 2560] in width and [0, 2560] in height, both in units of vp. 6141 6142The new width and height you set must meet the limits. 6143 6144This operation is not supported in a window in full-screen mode. 6145 6146> **NOTE** 6147> 6148> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [resize()](#resize9-1) instead. 6149 6150**System capability**: SystemCapability.WindowManager.WindowManager.Core 6151 6152**Parameters** 6153 6154| Name | Type | Mandatory | Description | 6155| ------ | ------ | --------- | ------------------------------------------------------------ | 6156| width | number | Yes | New width of the window, in px. The value must be an integer. | 6157| height | number | Yes | New height of the window, in px. The value must be an integer. | 6158 6159**Return value** 6160 6161| Type | Description | 6162| ------------------- | ------------------------------ | 6163| Promise<void> | Promise that returns no value. | 6164 6165**Example** 6166 6167```ts 6168import { BusinessError } from '@ohos.base'; 6169 6170let promise = windowClass.resetSize(500, 1000); 6171promise.then(() => { 6172 console.info('Succeeded in changing the window size.'); 6173}).catch((err: BusinessError) => { 6174 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 6175}); 6176``` 6177 6178### setWindowType<sup>(deprecated)</sup> 6179 6180setWindowType(type: WindowType, callback: AsyncCallback<void>): void 6181 6182Sets the type of this window. This API uses an asynchronous callback to return the result. 6183 6184**System API**: This is a system API. 6185 6186> **NOTE** 6187> 6188> This API is supported since API version 7 and deprecated since API version 9. 6189 6190**System capability**: SystemCapability.WindowManager.WindowManager.Core 6191 6192**Parameters** 6193 6194| Name | Type | Mandatory | Description | 6195| -------- | -------------------------- | --------- | ----------------------------------- | 6196| type | [WindowType](#windowtype7) | Yes | Window type. | 6197| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6198 6199**Example** 6200 6201```ts 6202import { BusinessError } from '@ohos.base'; 6203 6204let type = window.WindowType.TYPE_APP; 6205windowClass.setWindowType(type, (err: BusinessError) => { 6206 const errCode: number = err.code; 6207 if (errCode) { 6208 console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); 6209 return; 6210 } 6211 console.info('Succeeded in setting the window type.'); 6212}); 6213``` 6214 6215### setWindowType<sup>(deprecated)</sup> 6216 6217setWindowType(type: WindowType): Promise<void> 6218 6219Sets the type of this window. This API uses a promise to return the result. 6220 6221**System API**: This is a system API. 6222 6223> **NOTE** 6224> 6225> This API is supported since API version 7 and deprecated since API version 9. 6226 6227**System capability**: SystemCapability.WindowManager.WindowManager.Core 6228 6229**Parameters** 6230 6231| Name | Type | Mandatory | Description | 6232| ---- | -------------------------- | --------- | ------------ | 6233| type | [WindowType](#windowtype7) | Yes | Window type. | 6234 6235**Return value** 6236 6237| Type | Description | 6238| ------------------- | ------------------------------ | 6239| Promise<void> | Promise that returns no value. | 6240 6241**Example** 6242 6243```ts 6244import { BusinessError } from '@ohos.base'; 6245 6246let type = window.WindowType.TYPE_APP; 6247let promise = windowClass.setWindowType(type); 6248promise.then(() => { 6249 console.info('Succeeded in setting the window type.'); 6250}).catch((err: BusinessError) => { 6251 console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); 6252}); 6253``` 6254 6255### getProperties<sup>(deprecated)</sup> 6256 6257getProperties(callback: AsyncCallback<WindowProperties>): void 6258 6259Obtains the properties of this window. This API uses an asynchronous callback to return the result. 6260 6261> **NOTE** 6262> 6263> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 6264 6265**System capability**: SystemCapability.WindowManager.WindowManager.Core 6266 6267**Parameters** 6268 6269| Name | Type | Mandatory | Description | 6270| -------- | ---------------------------------------------------------- | --------- | ---------------------------------------------- | 6271| callback | AsyncCallback<[WindowProperties](#windowproperties)> | Yes | Callback used to return the window properties. | 6272 6273**Example** 6274 6275```ts 6276import { BusinessError } from '@ohos.base'; 6277 6278windowClass.getProperties((err: BusinessError, data) => { 6279 const errCode: number = err.code; 6280 if (errCode) { 6281 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 6282 return; 6283 } 6284 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 6285}); 6286``` 6287 6288### getProperties<sup>(deprecated)</sup> 6289 6290getProperties(): Promise<WindowProperties> 6291 6292Obtains the properties of this window. This API uses a promise to return the result. 6293 6294> **NOTE** 6295> 6296> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getWindowProperties()](#getwindowproperties9) instead. 6297 6298**System capability**: SystemCapability.WindowManager.WindowManager.Core 6299 6300**Return value** 6301 6302| Type | Description | 6303| ---------------------------------------------------- | --------------------------------------------- | 6304| Promise<[WindowProperties](#windowproperties)> | Promise used to return the window properties. | 6305 6306**Example** 6307 6308```ts 6309import { BusinessError } from '@ohos.base'; 6310 6311let promise = windowClass.getProperties(); 6312promise.then((data) => { 6313 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 6314}).catch((err: BusinessError) => { 6315 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 6316}); 6317``` 6318 6319### getAvoidArea<sup>(deprecated)</sup> 6320 6321getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 6322 6323Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. This API uses an asynchronous callback to return the result. 6324 6325> **NOTE** 6326> 6327> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 6328 6329**System capability**: SystemCapability.WindowManager.WindowManager.Core 6330 6331**Parameters** 6332 6333| Name | Type | Mandatory | Description | 6334| -------- | --------------------------------------------- | --------- | --------------------------------- | 6335| type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area. | 6336| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | 6337 6338**Example** 6339 6340```ts 6341import { BusinessError } from '@ohos.base'; 6342 6343let type = window.AvoidAreaType.TYPE_SYSTEM; 6344windowClass.getAvoidArea(type, (err: BusinessError, data) => { 6345 const errCode: number = err.code; 6346 if (errCode) { 6347 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 6348 return; 6349 } 6350 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 6351}); 6352``` 6353 6354### getAvoidArea<sup>(deprecated)</sup> 6355 6356getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 6357 6358Obtains the area where this window cannot be displayed, for example, the system bar area, notch, gesture area, and soft keyboard area. This API uses a promise to return the result. 6359 6360> **NOTE** 6361> 6362> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getWindowAvoidArea()](#getwindowavoidarea9) instead. 6363 6364**System capability**: SystemCapability.WindowManager.WindowManager.Core 6365 6366**Parameters** 6367 6368| Name | Type | Mandatory | Description | 6369| ---- | -------------------------------- | --------- | ----------------- | 6370| type | [AvoidAreaType](#avoidareatype7) | Yes | Type of the area. | 6371 6372**Return value** 6373 6374| Type | Description | 6375| --------------------------------------- | -------------------------------- | 6376| Promise<[AvoidArea](#avoidarea7)> | Promise used to return the area. | 6377 6378**Example** 6379 6380```ts 6381import { BusinessError } from '@ohos.base'; 6382 6383let type = window.AvoidAreaType.TYPE_SYSTEM; 6384let promise = windowClass.getAvoidArea(type); 6385promise.then((data) => { 6386 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 6387}).catch((err: BusinessError) => { 6388 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 6389}); 6390``` 6391 6392### setFullScreen<sup>(deprecated)</sup> 6393 6394setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 6395 6396Sets whether the window is in full-screen mode. This API uses an asynchronous callback to return the result. 6397 6398In full-screen mode, the window is displayed in full screen, and the status bar and navigation bar are not displayed. 6399 6400In non-full-screen mode, the status bar and navigation bar are displayed, and the window size does not overlap the positions of the status bar and navigation bar. 6401 6402> **NOTE** 6403> 6404> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) and [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) to implement the full-screen mode. 6405 6406**System capability**: SystemCapability.WindowManager.WindowManager.Core 6407 6408**Parameters** 6409 6410| Name | Type | Mandatory | Description | 6411| ------------ | ------------------------- | --------- | ------------------------------------------------------------ | 6412| isFullScreen | boolean | Yes | Whether to set full-screen mode. This setting affects the display of the status bar and navigation bar. The value **true** means to set full-screen mode, and **false** means the opposite. | 6413| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6414 6415**Example** 6416 6417```ts 6418import { BusinessError } from '@ohos.base'; 6419 6420let isFullScreen: boolean = true; 6421windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 6422 const errCode: number = err.code; 6423 if (errCode) { 6424 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 6425 return; 6426 } 6427 console.info('Succeeded in enabling the full-screen mode.'); 6428}); 6429``` 6430 6431### setFullScreen<sup>(deprecated)</sup> 6432 6433setFullScreen(isFullScreen: boolean): Promise<void> 6434 6435Sets whether the window is in full-screen mode. This API uses a promise to return the result. 6436 6437In full-screen mode, the window is displayed in full screen, and the status bar and navigation bar are not displayed. 6438 6439In non-full-screen mode, the status bar and navigation bar are displayed, and the window size does not overlap the positions of the status bar and navigation bar. 6440 6441> **NOTE** 6442> 6443> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9-1) and [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1) to implement the full-screen mode. 6444 6445**System capability**: SystemCapability.WindowManager.WindowManager.Core 6446 6447**Parameters** 6448 6449| Name | Type | Mandatory | Description | 6450| ------------ | ------- | --------- | ------------------------------------------------------------ | 6451| isFullScreen | boolean | Yes | Whether to set full-screen mode. This setting affects the display of the status bar and navigation bar. The value **true** means to set full-screen mode, and **false** means the opposite. | 6452 6453**Return value** 6454 6455| Type | Description | 6456| ------------------- | ------------------------------ | 6457| Promise<void> | Promise that returns no value. | 6458 6459**Example** 6460 6461```ts 6462import { BusinessError } from '@ohos.base'; 6463 6464let isFullScreen: boolean = true; 6465let promise = windowClass.setFullScreen(isFullScreen); 6466promise.then(() => { 6467 console.info('Succeeded in enabling the full-screen mode.'); 6468}).catch((err: BusinessError) => { 6469 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 6470}); 6471``` 6472 6473### setLayoutFullScreen<sup>(deprecated)</sup> 6474 6475setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 6476 6477Sets whether the window layout is immersive. This API uses an asynchronous callback to return the result. 6478 6479An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 6480 6481A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 6482 6483> **NOTE** 6484> 6485> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9) instead. 6486 6487**System capability**: SystemCapability.WindowManager.WindowManager.Core 6488 6489**Parameters** 6490 6491| Name | Type | Mandatory | Description | 6492| ------------------ | ------------------------- | --------- | ------------------------------------------------------------ | 6493| isLayoutFullScreen | boolean | Yes | Whether the window layout is immersive. This setting does not affect the display of the status bar and navigation bar. The value **true** means that the window layout is immersive, and **false** means the opposite. | 6494| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6495 6496**Example** 6497 6498```ts 6499import { BusinessError } from '@ohos.base'; 6500 6501let isLayoutFullScreen: boolean = true; 6502windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 6503 const errCode: number = err.code; 6504 if (errCode) { 6505 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 6506 return; 6507 } 6508 console.info('Succeeded in setting the window layout to full-screen mode.'); 6509}); 6510``` 6511 6512### setLayoutFullScreen<sup>(deprecated)</sup> 6513 6514setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 6515 6516Sets whether the window layout is immersive. This API uses a promise to return the result. 6517 6518An immersive layout means that the layout does not avoid the status bar and navigation bar, and components may overlap with them. 6519 6520A non-immersive layout means that the layout avoids the status bar and navigation bar, and components do not overlap with them. 6521 6522> **NOTE** 6523> 6524> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1) instead. 6525 6526**System capability**: SystemCapability.WindowManager.WindowManager.Core 6527 6528**Parameters** 6529 6530| Name | Type | Mandatory | Description | 6531| ------------------ | ------- | --------- | ------------------------------------------------------------ | 6532| isLayoutFullScreen | boolean | Yes | Whether the window layout is immersive. This setting does not affect the display of the status bar and navigation bar. The value **true** means that the window layout is immersive, and **false** means the opposite. | 6533 6534**Return value** 6535 6536| Type | Description | 6537| ------------------- | ------------------------------ | 6538| Promise<void> | Promise that returns no value. | 6539 6540**Example** 6541 6542```ts 6543import { BusinessError } from '@ohos.base'; 6544 6545let isLayoutFullScreen: boolean = true; 6546let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 6547promise.then(() => { 6548 console.info('Succeeded in setting the window layout to full-screen mode.'); 6549}).catch((err: BusinessError) => { 6550 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 6551}); 6552``` 6553 6554### setSystemBarEnable<sup>(deprecated)</sup> 6555 6556setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 6557 6558Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 6559 6560> **NOTE** 6561> 6562> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9) instead. 6563 6564**System capability**: SystemCapability.WindowManager.WindowManager.Core 6565 6566**Parameters** 6567 6568| Name | Type | Mandatory | Description | 6569| -------- | ----------------------------- | --------- | ------------------------------------------------------------ | 6570| names | Array<'status'\|'navigation'> | Yes | Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed. | 6571| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6572 6573**Example** 6574 6575```ts 6576// In this example, the status bar and navigation bar are not displayed. 6577import { BusinessError } from '@ohos.base'; 6578 6579let names: Array<'status' | 'navigation'> = []; 6580windowClass.setSystemBarEnable(names, (err: BusinessError) => { 6581 const errCode: number = err.code; 6582 if (errCode) { 6583 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 6584 return; 6585 } 6586 console.info('Succeeded in setting the system bar to be invisible.'); 6587}); 6588``` 6589 6590### setSystemBarEnable<sup>(deprecated)</sup> 6591 6592setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 6593 6594Sets whether to display the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 6595 6596> **NOTE** 6597> 6598> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowSystemBarEnable()](#setwindowsystembarenable9-1) instead. 6599 6600**System capability**: SystemCapability.WindowManager.WindowManager.Core 6601 6602**Parameters** 6603 6604| Name | Type | Mandatory | Description | 6605| ----- | ----------------------------- | --------- | ------------------------------------------------------------ | 6606| names | Array<'status'\|'navigation'> | Yes | Whether to display the status bar and navigation bar when the window is in full-screen mode.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed. | 6607 6608**Return value** 6609 6610| Type | Description | 6611| ------------------- | ------------------------------ | 6612| Promise<void> | Promise that returns no value. | 6613 6614**Example** 6615 6616```ts 6617// In this example, the status bar and navigation bar are not displayed. 6618import { BusinessError } from '@ohos.base'; 6619 6620let names: Array<'status' | 'navigation'> = []; 6621let promise = windowClass.setSystemBarEnable(names); 6622promise.then(() => { 6623 console.info('Succeeded in setting the system bar to be invisible.'); 6624}).catch((err: BusinessError) => { 6625 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 6626}); 6627``` 6628 6629### setSystemBarProperties<sup>(deprecated)</sup> 6630 6631setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 6632 6633Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses an asynchronous callback to return the result. 6634 6635> **NOTE** 6636> 6637> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9) instead. 6638 6639**System capability**: SystemCapability.WindowManager.WindowManager.Core 6640 6641**Parameters** 6642 6643| Name | Type | Mandatory | Description | 6644| ------------------- | ------------------------------------------- | --------- | ------------------------------------------------ | 6645| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar. | 6646| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6647 6648**Example** 6649 6650```ts 6651import { BusinessError } from '@ohos.base'; 6652 6653let SystemBarProperties: window.SystemBarProperties = { 6654 statusBarColor: '#ff00ff', 6655 navigationBarColor: '#00ff00', 6656 // The following properties are supported since API version 8. 6657 statusBarContentColor: '#ffffff', 6658 navigationBarContentColor: '#00ffff' 6659}; 6660windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 6661 const errCode: number = err.code; 6662 if (errCode) { 6663 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 6664 return; 6665 } 6666 console.info('Succeeded in setting the system bar properties.'); 6667}); 6668``` 6669 6670### setSystemBarProperties<sup>(deprecated)</sup> 6671 6672setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 6673 6674Sets the properties of the status bar and navigation bar when the window is in full-screen mode. This API uses a promise to return the result. 6675 6676> **NOTE** 6677> 6678> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowSystemBarProperties()](#setwindowsystembarproperties9-1) instead. 6679 6680**System capability**: SystemCapability.WindowManager.WindowManager.Core 6681 6682**Parameters** 6683 6684| Name | Type | Mandatory | Description | 6685| ------------------- | ------------------------------------------- | --------- | ------------------------------------------------ | 6686| SystemBarProperties | [SystemBarProperties](#systembarproperties) | Yes | Properties of the status bar and navigation bar. | 6687 6688**Return value** 6689 6690| Type | Description | 6691| ------------------- | ------------------------------ | 6692| Promise<void> | Promise that returns no value. | 6693 6694**Example** 6695 6696```ts 6697import { BusinessError } from '@ohos.base'; 6698 6699let SystemBarProperties: window.SystemBarProperties = { 6700 statusBarColor: '#ff00ff', 6701 navigationBarColor: '#00ff00', 6702 // The following properties are supported since API version 8. 6703 statusBarContentColor: '#ffffff', 6704 navigationBarContentColor: '#00ffff' 6705}; 6706let promise = windowClass.setSystemBarProperties(SystemBarProperties); 6707promise.then(() => { 6708 console.info('Succeeded in setting the system bar properties.'); 6709}).catch((err: BusinessError) => { 6710 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 6711}); 6712``` 6713 6714### loadContent<sup>(deprecated)</sup> 6715 6716loadContent(path: string, callback: AsyncCallback<void>): void 6717 6718Loads content from a page to this window. This API uses an asynchronous callback to return the result. 6719 6720> **NOTE** 6721> 6722> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9) instead. 6723 6724**System capability**: SystemCapability.WindowManager.WindowManager.Core 6725 6726**Parameters** 6727 6728| Name | Type | Mandatory | Description | 6729| -------- | ------------------------- | --------- | ------------------------------------------------------- | 6730| path | string | Yes | Path of the page from which the content will be loaded. | 6731| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6732 6733**Example** 6734 6735```ts 6736import { BusinessError } from '@ohos.base'; 6737 6738windowClass.loadContent('pages/page2/page2', (err: BusinessError) => { 6739 const errCode: number = err.code; 6740 if (errCode) { 6741 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6742 return; 6743 } 6744 console.info('Succeeded in loading the content.'); 6745}); 6746``` 6747 6748### loadContent<sup>(deprecated)</sup> 6749 6750loadContent(path: string): Promise<void> 6751 6752Loads content from a page to this window. This API uses a promise to return the result. 6753 6754> **NOTE** 6755> 6756> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setUIContent()](#setuicontent9-1) instead. 6757 6758**System capability**: SystemCapability.WindowManager.WindowManager.Core 6759 6760**Parameters** 6761 6762| Name | Type | Mandatory | Description | 6763| ---- | ------ | --------- | ------------------------------------------------------- | 6764| path | string | Yes | Path of the page from which the content will be loaded. | 6765 6766**Return value** 6767 6768| Type | Description | 6769| ------------------- | ------------------------------ | 6770| Promise<void> | Promise that returns no value. | 6771 6772**Example** 6773 6774```ts 6775import { BusinessError } from '@ohos.base'; 6776 6777let promise = windowClass.loadContent('pages/page2/page2'); 6778promise.then(() => { 6779 console.info('Succeeded in loading the content.'); 6780}).catch((err: BusinessError) => { 6781 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 6782}); 6783``` 6784 6785### isShowing<sup>(deprecated)</sup> 6786 6787isShowing(callback: AsyncCallback<boolean>): void 6788 6789Checks whether this window is displayed. This API uses an asynchronous callback to return the result. 6790 6791> **NOTE** 6792> 6793> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 6794 6795**System capability**: SystemCapability.WindowManager.WindowManager.Core 6796 6797**Parameters** 6798 6799| Name | Type | Mandatory | Description | 6800| -------- | ---------------------------- | --------- | ------------------------------------------------------------ | 6801| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the window is displayed, and **false** means the opposite. | 6802 6803**Example** 6804 6805```ts 6806import { BusinessError } from '@ohos.base'; 6807 6808windowClass.isShowing((err: BusinessError, data) => { 6809 const errCode: number = err.code; 6810 if (errCode) { 6811 console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err)); 6812 return; 6813 } 6814 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 6815}); 6816``` 6817 6818### isShowing<sup>(deprecated)</sup> 6819 6820isShowing(): Promise<boolean> 6821 6822Checks whether this window is displayed. This API uses a promise to return the result. 6823 6824> **NOTE** 6825> 6826> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isWindowShowing()](#iswindowshowing9) instead. 6827 6828**System capability**: SystemCapability.WindowManager.WindowManager.Core 6829 6830**Return value** 6831 6832| Type | Description | 6833| ---------------------- | ------------------------------------------------------------ | 6834| Promise<boolean> | Promise used to return the result. The value **true** means that the window is displayed, and **false** means the opposite. | 6835 6836**Example** 6837 6838```ts 6839import { BusinessError } from '@ohos.base'; 6840 6841let promise = windowClass.isShowing(); 6842promise.then((data) => { 6843 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 6844}).catch((err: BusinessError) => { 6845 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err)); 6846}); 6847``` 6848 6849### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 6850 6851on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 6852 6853Subscribes to the event indicating changes to the area where the window cannot be displayed. 6854 6855> **NOTE** 6856> 6857> This API is supported since API version 7 and deprecated since API version 9. Use [on('avoidAreaChange')](#onavoidareachange9) instead. 6858 6859**System capability**: SystemCapability.WindowManager.WindowManager.Core 6860 6861**Parameters** 6862 6863| Name | Type | Mandatory | Description | 6864| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ | 6865| 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. | 6866| callback | Callback<[AvoidArea](#avoidarea7)> | Yes | Callback used to return the area. | 6867 6868**Example** 6869 6870```ts 6871windowClass.on('systemAvoidAreaChange', (data) => { 6872 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 6873}); 6874``` 6875 6876### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 6877 6878off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 6879 6880Unsubscribes from the event indicating changes to the area where the window cannot be displayed. 6881 6882> **NOTE** 6883> 6884> This API is supported since API version 7 and deprecated since API version 9. Use [off('avoidAreaChange')](#offavoidareachange9) instead. 6885 6886**System capability**: SystemCapability.WindowManager.WindowManager.Core 6887 6888**Parameters** 6889 6890| Name | Type | Mandatory | Description | 6891| -------- | ---------------------------------------- | --------- | ------------------------------------------------------------ | 6892| 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. | 6893| callback | Callback<[AvoidArea](#avoidarea7)> | No | Callback used to return the area. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 6894 6895**Example** 6896 6897```ts 6898windowClass.off('systemAvoidAreaChange'); 6899``` 6900 6901### isSupportWideGamut<sup>(deprecated)</sup> 6902 6903isSupportWideGamut(callback: AsyncCallback<boolean>): void 6904 6905Checks whether this window supports the wide-gamut color space. This API uses an asynchronous callback to return the result. 6906 6907> **NOTE** 6908> 6909> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9) instead. 6910 6911**System capability**: SystemCapability.WindowManager.WindowManager.Core 6912 6913**Parameters** 6914 6915| Name | Type | Mandatory | Description | 6916| -------- | ---------------------------- | --------- | ------------------------------------------------------------ | 6917| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite. | 6918 6919**Example** 6920 6921```ts 6922import { BusinessError } from '@ohos.base'; 6923 6924windowClass.isSupportWideGamut((err: BusinessError, data) => { 6925 const errCode: number = err.code; 6926 if (errCode) { 6927 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 6928 return; 6929 } 6930 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 6931}); 6932``` 6933 6934### isSupportWideGamut<sup>(deprecated)</sup> 6935 6936isSupportWideGamut(): Promise<boolean> 6937 6938Checks whether this window supports the wide-gamut color space. This API uses a promise to return the result. 6939 6940> **NOTE** 6941> 6942> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1) instead. 6943 6944**System capability**: SystemCapability.WindowManager.WindowManager.Core 6945 6946**Return value** 6947 6948| Type | Description | 6949| ---------------------- | ------------------------------------------------------------ | 6950| Promise<boolean> | Promise used to return the result. The value **true** means that the wide-gamut color space is supported, and **false** means the opposite. | 6951 6952**Example** 6953 6954```ts 6955import { BusinessError } from '@ohos.base'; 6956 6957let promise = windowClass.isSupportWideGamut(); 6958promise.then((data) => { 6959 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 6960}).catch((err: BusinessError) => { 6961 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 6962}); 6963``` 6964 6965### setColorSpace<sup>(deprecated)</sup> 6966 6967setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 6968 6969Sets a color space for this window. This API uses an asynchronous callback to return the result. 6970 6971> **NOTE** 6972> 6973> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9) instead. 6974 6975**System capability**: SystemCapability.WindowManager.WindowManager.Core 6976 6977**Parameters** 6978 6979| Name | Type | Mandatory | Description | 6980| ---------- | -------------------------- | --------- | ----------------------------------- | 6981| colorSpace | [ColorSpace](#colorspace8) | Yes | Color space to set. | 6982| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6983 6984**Example** 6985 6986```ts 6987import { BusinessError } from '@ohos.base'; 6988 6989windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 6990 const errCode: number = err.code; 6991 if (errCode) { 6992 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 6993 return; 6994 } 6995 console.info('Succeeded in setting window colorspace.'); 6996}); 6997``` 6998 6999### setColorSpace<sup>(deprecated)</sup> 7000 7001setColorSpace(colorSpace:ColorSpace): Promise<void> 7002 7003Sets a color space for this window. This API uses a promise to return the result. 7004 7005> **NOTE** 7006> 7007> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setWindowColorSpace()](#setwindowcolorspace9-1) instead. 7008 7009**System capability**: SystemCapability.WindowManager.WindowManager.Core 7010 7011**Parameters** 7012 7013| Name | Type | Mandatory | Description | 7014| ---------- | -------------------------- | --------- | ------------------- | 7015| colorSpace | [ColorSpace](#colorspace8) | Yes | Color space to set. | 7016 7017**Return value** 7018 7019| Type | Description | 7020| ------------------- | ------------------------------ | 7021| Promise<void> | Promise that returns no value. | 7022 7023**Example** 7024 7025```ts 7026import { BusinessError } from '@ohos.base'; 7027 7028let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 7029promise.then(() => { 7030 console.info('Succeeded in setting window colorspace.'); 7031}).catch((err: BusinessError) => { 7032 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 7033}); 7034``` 7035 7036### getColorSpace<sup>(deprecated)</sup> 7037 7038getColorSpace(callback: AsyncCallback<ColorSpace>): void 7039 7040Obtains the color space of this window. This API uses an asynchronous callback to return the result. 7041 7042> **NOTE** 7043> 7044> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 7045 7046**System capability**: SystemCapability.WindowManager.WindowManager.Core 7047 7048**Parameters** 7049 7050| Name | Type | Mandatory | Description | 7051| -------- | ----------------------------------------------- | --------- | ------------------------------------------------------------ | 7052| callback | AsyncCallback<[ColorSpace](#colorspace8)> | Yes | Callback used to return the result. When the color space is obtained successfully, **err** is **undefined**, and **data** is the current color space. | 7053 7054**Example** 7055 7056```ts 7057import { BusinessError } from '@ohos.base'; 7058 7059windowClass.getColorSpace((err: BusinessError, data) => { 7060 const errCode: number = err.code; 7061 if (errCode) { 7062 console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err)); 7063 return; 7064 } 7065 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 7066}); 7067``` 7068 7069### getColorSpace<sup>(deprecated)</sup> 7070 7071getColorSpace(): Promise<ColorSpace> 7072 7073Obtains the color space of this window. This API uses a promise to return the result. 7074 7075> **NOTE** 7076> 7077> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getWindowColorSpace()](#getwindowcolorspace9) instead. 7078 7079**System capability**: SystemCapability.WindowManager.WindowManager.Core 7080 7081**Return value** 7082 7083| Type | Description | 7084| ----------------------------------------- | ----------------------------------------------- | 7085| Promise<[ColorSpace](#colorspace8)> | Promise used to return the current color space. | 7086 7087**Example** 7088 7089```ts 7090import { BusinessError } from '@ohos.base'; 7091 7092let promise = windowClass.getColorSpace(); 7093promise.then((data) => { 7094 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 7095}).catch((err: BusinessError) => { 7096 console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err)); 7097}); 7098``` 7099 7100### setBackgroundColor<sup>(deprecated)</sup> 7101 7102setBackgroundColor(color: string, callback: AsyncCallback<void>): void 7103 7104Sets 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 the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7105 7106> **NOTE** 7107> 7108> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 7109 7110**System capability**: SystemCapability.WindowManager.WindowManager.Core 7111 7112**Parameters** 7113 7114| Name | Type | Mandatory | Description | 7115| -------- | ------------------------- | --------- | ------------------------------------------------------------ | 7116| color | string | Yes | Background color to set. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**. | 7117| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7118 7119**Example** 7120 7121```ts 7122import { BusinessError } from '@ohos.base'; 7123 7124let color: string = '#00ff33'; 7125windowClass.setBackgroundColor(color, (err: BusinessError) => { 7126 const errCode: number = err.code; 7127 if (errCode) { 7128 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 7129 return; 7130 } 7131 console.info('Succeeded in setting the background color.'); 7132}); 7133``` 7134 7135### setBackgroundColor<sup>(deprecated)</sup> 7136 7137setBackgroundColor(color: string): Promise<void> 7138 7139Sets 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 the call of [loadContent](#loadcontent9) or [setUIContent()](#setuicontent9) takes effect. 7140 7141> **NOTE** 7142> 7143> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBackgroundColor()](#setwindowbackgroundcolor9) instead. 7144 7145**System capability**: SystemCapability.WindowManager.WindowManager.Core 7146 7147**Parameters** 7148 7149| Name | Type | Mandatory | Description | 7150| ----- | ------ | --------- | ------------------------------------------------------------ | 7151| color | string | Yes | Background color to set. The value is a hexadecimal RGB or ARGB color code and is case insensitive, for example, **#00FF00** or **#FF00FF00**. | 7152 7153**Return value** 7154 7155| Type | Description | 7156| ------------------- | ------------------------------ | 7157| Promise<void> | Promise that returns no value. | 7158 7159**Example** 7160 7161```ts 7162import { BusinessError } from '@ohos.base'; 7163 7164let color: string = '#00ff33'; 7165let promise = windowClass.setBackgroundColor(color); 7166promise.then(() => { 7167 console.info('Succeeded in setting the background color.'); 7168}).catch((err: BusinessError) => { 7169 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 7170}); 7171``` 7172 7173### setBrightness<sup>(deprecated)</sup> 7174 7175setBrightness(brightness: number, callback: AsyncCallback<void>): void 7176 7177Sets the screen brightness for this window. This API uses an asynchronous callback to return the result. 7178 7179When the screen brightness setting for the window takes effect, Control Panel cannot adjust the system screen brightness. It can do so only after the window screen brightness is restored to the default value. 7180 7181> **NOTE** 7182> 7183> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9) instead. 7184 7185**System capability**: SystemCapability.WindowManager.WindowManager.Core 7186 7187**Parameters** 7188 7189| Name | Type | Mandatory | Description | 7190| ---------- | ------------------------- | --------- | ------------------------------------------------------------ | 7191| brightness | number | Yes | Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness. | 7192| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7193 7194**Example** 7195 7196```ts 7197import { BusinessError } from '@ohos.base'; 7198 7199let brightness: number = 1; 7200windowClass.setBrightness(brightness, (err: BusinessError) => { 7201 const errCode: number = err.code; 7202 if (errCode) { 7203 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 7204 return; 7205 } 7206 console.info('Succeeded in setting the brightness.'); 7207}); 7208``` 7209 7210### setBrightness<sup>(deprecated)</sup> 7211 7212setBrightness(brightness: number): Promise<void> 7213 7214Sets the screen brightness for this window. This API uses a promise to return the result. 7215 7216When the screen brightness setting for the window takes effect, Control Panel cannot adjust the system screen brightness. It can do so only after the window screen brightness is restored to the default value. 7217 7218> **NOTE** 7219> 7220> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowBrightness()](#setwindowbrightness9-1) instead. 7221 7222**System capability**: SystemCapability.WindowManager.WindowManager.Core 7223 7224**Parameters** 7225 7226| Name | Type | Mandatory | Description | 7227| ---------- | ------ | --------- | ------------------------------------------------------------ | 7228| brightness | number | Yes | Brightness to set. The value is a floating point number in the range [0.0, 1.0] or **-1.0**. The value **1.0** means the brightest, and **-1.0** means the default brightness. | 7229 7230**Return value** 7231 7232| Type | Description | 7233| ------------------- | ------------------------------ | 7234| Promise<void> | Promise that returns no value. | 7235 7236**Example** 7237 7238```ts 7239import { BusinessError } from '@ohos.base'; 7240 7241let brightness: number = 1; 7242let promise = windowClass.setBrightness(brightness); 7243promise.then(() => { 7244 console.info('Succeeded in setting the brightness.'); 7245}).catch((err: BusinessError) => { 7246 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 7247}); 7248``` 7249 7250### setDimBehind<sup>(deprecated)</sup> 7251 7252setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 7253 7254Sets the dimness of the window that is not on top. This API uses an asynchronous callback to return the result. 7255 7256> **NOTE** 7257> 7258> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 7259 7260**System capability**: SystemCapability.WindowManager.WindowManager.Core 7261 7262**Parameters** 7263 7264| Name | Type | Mandatory | Description | 7265| -------------- | ------------------------- | --------- | ------------------------------------------------------------ | 7266| dimBehindValue | number | Yes | Dimness of the window to set. The value range is [0.0, 1.0], and the value **1.0** means the dimmest. | 7267| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7268 7269**Example** 7270 7271```ts 7272import { BusinessError } from '@ohos.base'; 7273 7274windowClass.setDimBehind(0.5, (err: BusinessError) => { 7275 const errCode: number = err.code; 7276 if (errCode) { 7277 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 7278 return; 7279 } 7280 console.info('Succeeded in setting the dimness.'); 7281}); 7282``` 7283 7284### setDimBehind<sup>(deprecated)</sup> 7285 7286setDimBehind(dimBehindValue: number): Promise<void> 7287 7288Sets the dimness of the window that is not on top. This API uses a promise to return the result. 7289 7290> **NOTE** 7291> 7292> This API cannot be used. This API is supported since API version 7 and deprecated since API version 9. 7293 7294**System capability**: SystemCapability.WindowManager.WindowManager.Core 7295 7296**Parameters** 7297 7298| Name | Type | Mandatory | Description | 7299| -------------- | ------ | --------- | ------------------------------------------------------------ | 7300| dimBehindValue | number | Yes | Dimness of the window to set. The value ranges from 0 to 1. The value **1** indicates the dimmest. | 7301 7302**Return value** 7303 7304| Type | Description | 7305| ------------------- | ------------------------------ | 7306| Promise<void> | Promise that returns no value. | 7307 7308**Example** 7309 7310```ts 7311import { BusinessError } from '@ohos.base'; 7312 7313let promise = windowClass.setDimBehind(0.5); 7314promise.then(() => { 7315 console.info('Succeeded in setting the dimness.'); 7316}).catch((err: BusinessError) => { 7317 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 7318}); 7319``` 7320 7321### setFocusable<sup>(deprecated)</sup> 7322 7323setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 7324 7325Sets whether this window can gain focus. This API uses an asynchronous callback to return the result. 7326 7327> **NOTE** 7328> 7329> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9) instead. 7330 7331**System capability**: SystemCapability.WindowManager.WindowManager.Core 7332 7333**Parameters** 7334 7335| Name | Type | Mandatory | Description | 7336| ----------- | ------------------------- | --------- | ------------------------------------------------------------ | 7337| isFocusable | boolean | Yes | Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 7338| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7339 7340**Example** 7341 7342```ts 7343import { BusinessError } from '@ohos.base'; 7344 7345let isFocusable: boolean = true; 7346windowClass.setFocusable(isFocusable, (err: BusinessError) => { 7347 const errCode: number = err.code; 7348 if (errCode) { 7349 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 7350 return; 7351 } 7352 console.info('Succeeded in setting the window to be focusable.'); 7353}); 7354``` 7355 7356### setFocusable<sup>(deprecated)</sup> 7357 7358setFocusable(isFocusable: boolean): Promise<void> 7359 7360Sets whether this window can gain focus. This API uses a promise to return the result. 7361 7362> **NOTE** 7363> 7364> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowFocusable()](#setwindowfocusable9-1) instead. 7365 7366**System capability**: SystemCapability.WindowManager.WindowManager.Core 7367 7368**Parameters** 7369 7370| Name | Type | Mandatory | Description | 7371| ----------- | ------- | --------- | ------------------------------------------------------------ | 7372| isFocusable | boolean | Yes | Whether the window can gain focus. The value **true** means that the window can gain focus, and **false** means the opposite. | 7373 7374**Return value** 7375 7376| Type | Description | 7377| ------------------- | ------------------------------ | 7378| Promise<void> | Promise that returns no value. | 7379 7380**Example** 7381 7382```ts 7383import { BusinessError } from '@ohos.base'; 7384 7385let isFocusable: boolean = true; 7386let promise = windowClass.setFocusable(isFocusable); 7387promise.then(() => { 7388 console.info('Succeeded in setting the window to be focusable.'); 7389}).catch((err: BusinessError) => { 7390 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 7391}); 7392``` 7393 7394### setKeepScreenOn<sup>(deprecated)</sup> 7395 7396setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 7397 7398Sets whether to keep the screen always on. This API uses an asynchronous callback to return the result. 7399 7400> **NOTE** 7401> 7402> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9) instead. 7403 7404**System capability**: SystemCapability.WindowManager.WindowManager.Core 7405 7406**Parameters** 7407 7408| Name | Type | Mandatory | Description | 7409| -------------- | ------------------------- | --------- | ------------------------------------------------------------ | 7410| isKeepScreenOn | boolean | Yes | Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite. | 7411| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7412 7413**Example** 7414 7415```ts 7416import { BusinessError } from '@ohos.base'; 7417 7418let isKeepScreenOn: boolean = true; 7419windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 7420 const errCode: number = err.code; 7421 if (errCode) { 7422 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 7423 return; 7424 } 7425 console.info('Succeeded in setting the screen to be always on.'); 7426}); 7427``` 7428 7429### setKeepScreenOn<sup>(deprecated)</sup> 7430 7431setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 7432 7433Sets whether to keep the screen always on. This API uses a promise to return the result. 7434 7435> **NOTE** 7436> 7437> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setWindowKeepScreenOn()](#setwindowkeepscreenon9-1) instead. 7438 7439**System capability**: SystemCapability.WindowManager.WindowManager.Core 7440 7441**Parameters** 7442 7443| Name | Type | Mandatory | Description | 7444| -------------- | ------- | --------- | ------------------------------------------------------------ | 7445| isKeepScreenOn | boolean | Yes | Whether to keep the screen always on. The value **true** means to keep the screen always on, and **false** means the opposite. | 7446 7447**Return value** 7448 7449| Type | Description | 7450| ------------------- | ------------------------------ | 7451| Promise<void> | Promise that returns no value. | 7452 7453**Example** 7454 7455```ts 7456import { BusinessError } from '@ohos.base'; 7457 7458let isKeepScreenOn: boolean = true; 7459let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 7460promise.then(() => { 7461 console.info('Succeeded in setting the screen to be always on.'); 7462}).catch((err: BusinessError) => { 7463 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 7464}); 7465``` 7466 7467### setOutsideTouchable<sup>(deprecated)</sup> 7468 7469setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 7470 7471Sets whether the area outside the subwindow is touchable. This API uses an asynchronous callback to return the result. 7472 7473> **NOTE** 7474> 7475> This API is supported since API version 7 and deprecated since API version 9. 7476> 7477> Since API version 9, the area outside the subwindow is touchable by default. This API is no longer supported and no substitute API is provided. 7478 7479**System capability**: SystemCapability.WindowManager.WindowManager.Core 7480 7481**Parameters** 7482 7483| Name | Type | Mandatory | Description | 7484| --------- | ------------------------- | --------- | ------------------------------------------------------------ | 7485| touchable | boolean | Yes | Whether the area outside the subwindow is touchable. The value **true** means the area outside the subwindow is touchable, and **false** means the opposite. | 7486| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7487 7488**Example** 7489 7490```ts 7491import { BusinessError } from '@ohos.base'; 7492 7493if (!windowClass) { 7494 console.info('Failed to load the content. Cause: windowClass is null'); 7495} 7496else { 7497 (windowClass as window.Window).setOutsideTouchable(true, (err: BusinessError) => { 7498 const errCode: number = err.code; 7499 if (errCode) { 7500 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 7501 return; 7502 } 7503 console.info('Succeeded in setting the area to be touchable.'); 7504 }); 7505} 7506``` 7507 7508### setOutsideTouchable<sup>(deprecated)</sup> 7509 7510setOutsideTouchable(touchable: boolean): Promise<void> 7511 7512Sets whether the area outside the subwindow is touchable. This API uses a promise to return the result. 7513 7514> **NOTE** 7515> 7516> This API is supported since API version 7 and deprecated since API version 9. 7517> 7518> Since API version 9, the area outside the subwindow is touchable by default. This API is no longer supported and no substitute API is provided. 7519 7520**System capability**: SystemCapability.WindowManager.WindowManager.Core 7521 7522**Parameters** 7523 7524| Name | Type | Mandatory | Description | 7525| --------- | ------- | --------- | ------------------------------------------------------------ | 7526| touchable | boolean | Yes | Whether the area outside the subwindow is touchable. The value **true** means the area outside the subwindow is touchable, and **false** means the opposite. | 7527 7528**Return value** 7529 7530| Type | Description | 7531| ------------------- | ------------------------------ | 7532| Promise<void> | Promise that returns no value. | 7533 7534**Example** 7535 7536```ts 7537import { BusinessError } from '@ohos.base'; 7538 7539if (!windowClass) { 7540 console.info('Failed to load the content. Cause: windowClass is null'); 7541} 7542else { 7543let promise = (windowClass as window.Window).setOutsideTouchable(true); 7544promise.then(() => { 7545 console.info('Succeeded in setting the area to be touchable.'); 7546}).catch((err: BusinessError) => { 7547 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 7548}); 7549} 7550``` 7551 7552### setPrivacyMode<sup>(deprecated)</sup> 7553 7554setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 7555 7556Sets whether this window is in privacy mode. This API uses an asynchronous callback to return the result. 7557 7558A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 7559 7560> **NOTE** 7561> 7562> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9) instead. 7563 7564**System capability**: SystemCapability.WindowManager.WindowManager.Core 7565 7566**Parameters** 7567 7568| Name | Type | Mandatory | Description | 7569| ------------- | ------------------------- | --------- | ------------------------------------------------------------ | 7570| isPrivacyMode | boolean | Yes | Whether the window is in privacy mode. The value **true** means that the window is in privacy mode, and **false** means the opposite. | 7571| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7572 7573**Example** 7574 7575```ts 7576import { BusinessError } from '@ohos.base'; 7577 7578let isPrivacyMode: boolean = true; 7579windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 7580 const errCode: number = err.code; 7581 if (errCode) { 7582 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 7583 return; 7584 } 7585 console.info('Succeeded in setting the window to privacy mode.'); 7586}); 7587``` 7588 7589### setPrivacyMode<sup>(deprecated)</sup> 7590 7591setPrivacyMode(isPrivacyMode: boolean): Promise<void> 7592 7593Sets whether this window is in privacy mode. This API uses a promise to return the result. 7594 7595A window in privacy mode cannot be captured or recorded. This API can be used in scenarios where screen capture or recording is disabled. 7596 7597> **NOTE** 7598> 7599> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowPrivacyMode()](#setwindowprivacymode9-1) instead. 7600 7601**System capability**: SystemCapability.WindowManager.WindowManager.Core 7602 7603**Parameters** 7604 7605| Name | Type | Mandatory | Description | 7606| ------------- | ------- | --------- | ------------------------------------------------------------ | 7607| isPrivacyMode | boolean | Yes | Whether the window is in privacy mode. The value **true** means that the window is in privacy mode, and **false** means the opposite. | 7608 7609**Return value** 7610 7611| Type | Description | 7612| ------------------- | ------------------------------ | 7613| Promise<void> | Promise that returns no value. | 7614 7615**Example** 7616 7617```ts 7618import { BusinessError } from '@ohos.base'; 7619 7620let isPrivacyMode: boolean = true; 7621let promise = windowClass.setPrivacyMode(isPrivacyMode); 7622promise.then(() => { 7623 console.info('Succeeded in setting the window to privacy mode.'); 7624}).catch((err: BusinessError) => { 7625 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 7626}); 7627``` 7628 7629### setTouchable<sup>(deprecated)</sup> 7630 7631setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 7632 7633Sets whether this window is touchable. This API uses an asynchronous callback to return the result. 7634 7635> **NOTE** 7636> 7637> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9) instead. 7638 7639**System capability**: SystemCapability.WindowManager.WindowManager.Core 7640 7641**Parameters** 7642 7643| Name | Type | Mandatory | Description | 7644| ----------- | ------------------------- | --------- | ------------------------------------------------------------ | 7645| isTouchable | boolean | Yes | Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite. | 7646| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 7647 7648**Example** 7649 7650```ts 7651import { BusinessError } from '@ohos.base'; 7652 7653let isTouchable = true; 7654if (!windowClass) { 7655 console.info('Failed to load the content. Cause: windowClass is null'); 7656} 7657else { 7658 (windowClass as window.Window).setTouchable(isTouchable, (err: BusinessError) => { 7659 const errCode: number = err.code; 7660 if (errCode) { 7661 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 7662 return; 7663 } 7664 console.info('Succeeded in setting the window to be touchable.'); 7665 }); 7666} 7667``` 7668 7669### setTouchable<sup>(deprecated)</sup> 7670 7671setTouchable(isTouchable: boolean): Promise<void> 7672 7673Sets whether this window is touchable. This API uses a promise to return the result. 7674 7675> **NOTE** 7676> 7677> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setWindowTouchable()](#setwindowtouchable9-1) instead. 7678 7679**System capability**: SystemCapability.WindowManager.WindowManager.Core 7680 7681**Parameters** 7682 7683| Name | Type | Mandatory | Description | 7684| ----------- | ------- | --------- | ------------------------------------------------------------ | 7685| isTouchable | boolean | Yes | Whether the window is touchable. The value **true** means that the window is touchable, and **false** means the opposite. | 7686 7687**Return value** 7688 7689| Type | Description | 7690| ------------------- | ------------------------------ | 7691| Promise<void> | Promise that returns no value. | 7692 7693**Example** 7694 7695```ts 7696import { BusinessError } from '@ohos.base'; 7697 7698let isTouchable = true; 7699let promise = windowClass.setTouchable(isTouchable); 7700promise.then(() => { 7701 console.info('Succeeded in setting the window to be touchable.'); 7702}).catch((err: BusinessError) => { 7703 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 7704}); 7705``` 7706 7707## WindowStageEventType<sup>9+</sup> 7708 7709Describes the lifecycle of a window stage. 7710 7711**Model restriction**: This API can be used only in the stage model. 7712 7713**System capability**: SystemCapability.WindowManager.WindowManager.Core 7714 7715| Name | Value | Description | 7716| -------- | ----- | ---------------------------------------------- | 7717| SHOWN | 1 | The window stage is running in the foreground. | 7718| ACTIVE | 2 | The window stage gains focus. | 7719| INACTIVE | 3 | The window stage loses focus. | 7720| HIDDEN | 4 | The window stage is running in the background. | 7721 7722## WindowStage<sup>9+</sup> 7723 7724Implements a window manager, which manages each basic window unit, that is, [Window](#window) instance. 7725 7726Before calling any of the following APIs, you must use [onWindowStageCreate()](js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) to create a **WindowStage** instance. 7727 7728### getMainWindow<sup>9+</sup> 7729 7730getMainWindow(callback: AsyncCallback<Window>): void 7731 7732Obtains the main window of this window stage. This API uses an asynchronous callback to return the result. 7733 7734**Model restriction**: This API can be used only in the stage model. 7735 7736**System capability**: SystemCapability.WindowManager.WindowManager.Core 7737 7738**Parameters** 7739 7740| Name | Type | Mandatory | Description | 7741| -------- | -------------------------------------- | --------- | ---------------------------------------- | 7742| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the main window. | 7743 7744**Error codes** 7745 7746For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 7747 7748| ID | Error Message | 7749| ------- | ------------------------------ | 7750| 1300002 | This window state is abnormal. | 7751| 1300005 | This window stage is abnormal. | 7752 7753**Example** 7754 7755```ts 7756import UIAbility from '@ohos.app.ability.UIAbility'; 7757import window from '@ohos.window'; 7758import { BusinessError } from '@ohos.base'; 7759 7760export default class EntryAbility extends UIAbility { 7761 // ... 7762 7763 onWindowStageCreate(windowStage: window.WindowStage) { 7764 console.log('onWindowStageCreate'); 7765 let windowClass: window.Window | null = null; 7766 windowStage.getMainWindow((err: BusinessError, data) => { 7767 const errCode: number = err.code; 7768 if (errCode) { 7769 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 7770 return; 7771 } 7772 windowClass = data; 7773 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7774 }); 7775 } 7776}; 7777``` 7778 7779### getMainWindow<sup>9+</sup> 7780 7781getMainWindow(): Promise<Window> 7782 7783Obtains the main window of this window stage. This API uses a promise to return the result. 7784 7785**Model restriction**: This API can be used only in the stage model. 7786 7787**System capability**: SystemCapability.WindowManager.WindowManager.Core 7788 7789**Return value** 7790 7791| Type | Description | 7792| -------------------------------- | --------------------------------------- | 7793| Promise<[Window](#window)> | Promise used to return the main window. | 7794 7795**Error codes** 7796 7797For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 7798 7799| ID | Error Message | 7800| ------- | ------------------------------ | 7801| 1300002 | This window state is abnormal. | 7802| 1300005 | This window stage is abnormal. | 7803 7804**Example** 7805 7806```ts 7807import UIAbility from '@ohos.app.ability.UIAbility'; 7808import window from '@ohos.window'; 7809import { BusinessError } from '@ohos.base'; 7810 7811export default class EntryAbility extends UIAbility { 7812 // ... 7813 7814 onWindowStageCreate(windowStage: window.WindowStage) { 7815 console.log('onWindowStageCreate'); 7816 let windowClass: window.Window | null = null; 7817 let promise = windowStage.getMainWindow(); 7818 promise.then((data) => { 7819 windowClass = data; 7820 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7821 }).catch((err: BusinessError) => { 7822 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 7823 }); 7824 } 7825}; 7826``` 7827 7828### getMainWindowSync<sup>9+</sup> 7829 7830getMainWindowSync(): Window 7831 7832Obtains the main window of this window stage. 7833 7834**Model restriction**: This API can be used only in the stage model. 7835 7836**System capability**: SystemCapability.WindowManager.WindowManager.Core 7837 7838**Return value** 7839 7840| Type | Description | 7841| ----------------- | ----------------------- | 7842| [Window](#window) | return the main window. | 7843 7844**Error codes** 7845 7846For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 7847 7848| ID | Error Message | 7849| ------- | ------------------------------ | 7850| 1300002 | This window state is abnormal. | 7851| 1300005 | This window stage is abnormal. | 7852 7853**Example** 7854 7855```ts 7856import UIAbility from '@ohos.app.ability.UIAbility'; 7857import window from '@ohos.window'; 7858 7859export default class EntryAbility extends UIAbility { 7860 // ... 7861 7862 onWindowStageCreate(windowStage: window.WindowStage) { 7863 console.log('onWindowStageCreate'); 7864 try { 7865 let windowClass = windowStage.getMainWindowSync(); 7866 } catch (exception) { 7867 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception)); 7868 } 7869 } 7870}; 7871``` 7872 7873### createSubWindow<sup>9+</sup> 7874 7875createSubWindow(name: string, callback: AsyncCallback<Window>): void 7876 7877Creates a subwindow for this window stage. This API uses an asynchronous callback to return the result. 7878 7879**Model restriction**: This API can be used only in the stage model. 7880 7881**System capability**: SystemCapability.WindowManager.WindowManager.Core 7882 7883**Parameters** 7884 7885| Name | Type | Mandatory | Description | 7886| -------- | -------------------------------------- | --------- | -------------------------------------- | 7887| name | string | Yes | Name of the subwindow. | 7888| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow. | 7889 7890**Error codes** 7891 7892For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 7893 7894| ID | Error Message | 7895| ------- | ------------------------------ | 7896| 1300002 | This window state is abnormal. | 7897| 1300005 | This window stage is abnormal. | 7898 7899**Example** 7900 7901```ts 7902import UIAbility from '@ohos.app.ability.UIAbility'; 7903import window from '@ohos.window'; 7904import { BusinessError } from '@ohos.base'; 7905 7906export default class EntryAbility extends UIAbility { 7907 // ... 7908 7909 onWindowStageCreate(windowStage: window.WindowStage) { 7910 console.log('onWindowStageCreate'); 7911 let windowClass: window.Window | null = null; 7912 try { 7913 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 7914 const errCode: number = err.code; 7915 if (errCode) { 7916 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 7917 return; 7918 } 7919 windowClass = data; 7920 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7921 if (!windowClass) { 7922 console.info('Failed to load the content. Cause: windowClass is null'); 7923 } 7924 else { 7925 (windowClass as window.Window).resetSize(500, 1000); 7926 } 7927 }); 7928 7929 } catch (exception) { 7930 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 7931 } 7932 } 7933}; 7934``` 7935### createSubWindow<sup>9+</sup> 7936 7937createSubWindow(name: string): Promise<Window> 7938 7939Creates a subwindow for this window stage. This API uses a promise to return the result. 7940 7941**Model restriction**: This API can be used only in the stage model. 7942 7943**System capability**: SystemCapability.WindowManager.WindowManager.Core 7944 7945**Parameters** 7946 7947| Name | Type | Mandatory | Description | 7948| ---- | ------ | --------- | ---------------------- | 7949| name | string | Yes | Name of the subwindow. | 7950 7951**Return value** 7952 7953| Type | Description | 7954| -------------------------------- | ------------------------------------- | 7955| Promise<[Window](#window)> | Promise used to return the subwindow. | 7956 7957**Error codes** 7958 7959For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 7960 7961| ID | Error Message | 7962| ------- | ------------------------------ | 7963| 1300002 | This window state is abnormal. | 7964| 1300005 | This window stage is abnormal. | 7965 7966**Example** 7967 7968```ts 7969import UIAbility from '@ohos.app.ability.UIAbility'; 7970import window from '@ohos.window'; 7971import { BusinessError } from '@ohos.base'; 7972 7973export default class EntryAbility extends UIAbility { 7974 // ... 7975 7976 onWindowStageCreate(windowStage: window.WindowStage) { 7977 console.log('onWindowStageCreate'); 7978 let windowClass: window.Window | null = null; 7979 try { 7980 let promise = windowStage.createSubWindow('mySubWindow'); 7981 promise.then((data) => { 7982 windowClass = data; 7983 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7984 }).catch((err: BusinessError) => { 7985 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 7986 }); 7987 } catch (exception) { 7988 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 7989 } 7990 } 7991}; 7992``` 7993 7994### getSubWindow<sup>9+</sup> 7995 7996getSubWindow(callback: AsyncCallback<Array<Window>>): void 7997 7998Obtains all the subwindows of this window stage. This API uses an asynchronous callback to return the result. 7999 8000**Model restriction**: This API can be used only in the stage model. 8001 8002**System capability**: SystemCapability.WindowManager.WindowManager.Core 8003 8004**Parameters** 8005 8006| Name | Type | Mandatory | Description | 8007| -------- | --------------------------------------------------- | --------- | ------------------------------------------- | 8008| callback | AsyncCallback<Array<[Window](#window)>> | Yes | Callback used to return all the subwindows. | 8009 8010**Error codes** 8011 8012For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8013 8014| ID | Error Message | 8015| ------- | ------------------------------ | 8016| 1300005 | This window stage is abnormal. | 8017 8018**Example** 8019 8020```ts 8021import UIAbility from '@ohos.app.ability.UIAbility'; 8022import window from '@ohos.window'; 8023import { BusinessError } from '@ohos.base'; 8024 8025export default class EntryAbility extends UIAbility { 8026 // ... 8027 8028 onWindowStageCreate(windowStage: window.WindowStage) { 8029 console.log('onWindowStageCreate'); 8030 let windowClass: window.Window[] = []; 8031 windowStage.getSubWindow((err: BusinessError, data) => { 8032 const errCode: number = err.code; 8033 if (errCode) { 8034 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 8035 return; 8036 } 8037 windowClass = data; 8038 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 8039 }); 8040 } 8041}; 8042``` 8043### getSubWindow<sup>9+</sup> 8044 8045getSubWindow(): Promise<Array<Window>> 8046 8047Obtains all the subwindows of this window stage. This API uses a promise to return the result. 8048 8049**Model restriction**: This API can be used only in the stage model. 8050 8051**System capability**: SystemCapability.WindowManager.WindowManager.Core 8052 8053**Return value** 8054 8055| Type | Description | 8056| --------------------------------------------- | ------------------------------------------ | 8057| Promise<Array<[Window](#window)>> | Promise used to return all the subwindows. | 8058 8059**Error codes** 8060 8061For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8062 8063| ID | Error Message | 8064| ------- | ------------------------------ | 8065| 1300005 | This window stage is abnormal. | 8066 8067**Example** 8068 8069```ts 8070import UIAbility from '@ohos.app.ability.UIAbility'; 8071import window from '@ohos.window'; 8072import { BusinessError } from '@ohos.base'; 8073 8074export default class EntryAbility extends UIAbility { 8075 // ... 8076 8077 onWindowStageCreate(windowStage: window.WindowStage) { 8078 console.log('onWindowStageCreate'); 8079 let windowClass: window.Window[] = []; 8080 let promise = windowStage.getSubWindow(); 8081 promise.then((data) => { 8082 windowClass = data; 8083 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 8084 }).catch((err: BusinessError) => { 8085 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 8086 }) 8087 } 8088}; 8089``` 8090### loadContent<sup>9+</sup> 8091 8092loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 8093 8094Loads 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. 8095 8096**Model restriction**: This API can be used only in the stage model. 8097 8098**System capability**: SystemCapability.WindowManager.WindowManager.Core 8099 8100**Parameters** 8101 8102| Name | Type | Mandatory | Description | 8103| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 8104| path | string | Yes | Path of the page from which the content will be loaded. | 8105| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | Yes | A storage unit, which provides storage for variable state properties and non-variable state properties of an application. | 8106| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8107 8108**Error codes** 8109 8110For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8111 8112| ID | Error Message | 8113| ------- | ------------------------------ | 8114| 1300002 | This window state is abnormal. | 8115| 1300005 | This window stage is abnormal. | 8116 8117**Example** 8118 8119```ts 8120import UIAbility from '@ohos.app.ability.UIAbility'; 8121import window from '@ohos.window'; 8122import { BusinessError } from '@ohos.base'; 8123 8124export default class EntryAbility extends UIAbility { 8125 // ... 8126 8127 storage: LocalStorage = new LocalStorage(); 8128 8129 onWindowStageCreate(windowStage: window.WindowStage) { 8130 this.storage.setOrCreate('storageSimpleProp', 121); 8131 console.log('onWindowStageCreate'); 8132 try { 8133 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 8134 const errCode: number = err.code; 8135 if (errCode) { 8136 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 8137 return; 8138 } 8139 console.info('Succeeded in loading the content.'); 8140 }); 8141 } catch (exception) { 8142 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 8143 } 8144 } 8145}; 8146``` 8147 8148### loadContent<sup>9+</sup> 8149 8150loadContent(path: string, storage?: LocalStorage): Promise<void> 8151 8152Loads 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. 8153 8154**Model restriction**: This API can be used only in the stage model. 8155 8156**System capability**: SystemCapability.WindowManager.WindowManager.Core 8157 8158**Parameters** 8159 8160| Name | Type | Mandatory | Description | 8161| ------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 8162| path | string | Yes | Path of the page from which the content will be loaded. | 8163| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | No | A storage unit, which provides storage for variable state properties and non-variable state properties of an application. | 8164 8165**Return value** 8166 8167| Type | Description | 8168| ------------------- | ------------------------------ | 8169| Promise<void> | Promise that returns no value. | 8170 8171**Error codes** 8172 8173For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8174 8175| ID | Error Message | 8176| ------- | ------------------------------ | 8177| 1300002 | This window state is abnormal. | 8178| 1300005 | This window stage is abnormal. | 8179 8180**Example** 8181 8182```ts 8183import UIAbility from '@ohos.app.ability.UIAbility'; 8184import window from '@ohos.window'; 8185import { BusinessError } from '@ohos.base'; 8186 8187export default class EntryAbility extends UIAbility { 8188 // ... 8189 8190 storage: LocalStorage = new LocalStorage(); 8191 8192 onWindowStageCreate(windowStage: window.WindowStage) { 8193 this.storage.setOrCreate('storageSimpleProp', 121); 8194 console.log('onWindowStageCreate'); 8195 try { 8196 let promise = windowStage.loadContent('pages/page2', this.storage); 8197 promise.then(() => { 8198 console.info('Succeeded in loading the content.'); 8199 }).catch((err: BusinessError) => { 8200 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 8201 }); 8202 } catch (exception) { 8203 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 8204 } 8205 ; 8206 } 8207}; 8208``` 8209 8210### loadContent<sup>9+</sup> 8211 8212loadContent(path: string, callback: AsyncCallback<void>): void 8213 8214Loads content from a page to this window stage. This API uses an asynchronous callback to return the result. 8215 8216**Model restriction**: This API can be used only in the stage model. 8217 8218**System capability**: SystemCapability.WindowManager.WindowManager.Core 8219 8220**Parameters** 8221 8222| Name | Type | Mandatory | Description | 8223| -------- | ------------------------- | --------- | ------------------------------------------------------- | 8224| path | string | Yes | Path of the page from which the content will be loaded. | 8225| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 8226 8227**Error codes** 8228 8229For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8230 8231| ID | Error Message | 8232| ------- | ------------------------------ | 8233| 1300002 | This window state is abnormal. | 8234| 1300005 | This window stage is abnormal. | 8235 8236**Example** 8237 8238```ts 8239import UIAbility from '@ohos.app.ability.UIAbility'; 8240import window from '@ohos.window'; 8241import { BusinessError } from '@ohos.base'; 8242 8243export default class EntryAbility extends UIAbility { 8244 // ... 8245 8246 onWindowStageCreate(windowStage: window.WindowStage) { 8247 console.log('onWindowStageCreate'); 8248 try { 8249 windowStage.loadContent('pages/page2', (err: BusinessError) => { 8250 const errCode: number = err.code; 8251 if (errCode) { 8252 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 8253 return; 8254 } 8255 console.info('Succeeded in loading the content.'); 8256 }); 8257 } catch (exception) { 8258 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 8259 } 8260 } 8261}; 8262``` 8263 8264### on('windowStageEvent')<sup>9+</sup> 8265 8266on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 8267 8268Subscribes to the window stage lifecycle change event. 8269 8270**Model restriction**: This API can be used only in the stage model. 8271 8272**System capability**: SystemCapability.WindowManager.WindowManager.Core 8273 8274**Parameters** 8275 8276| Name | Type | Mandatory | Description | 8277| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 8278| type | string | Yes | Event type. The value is fixed at **'windowStageEvent'**, indicating the window stage lifecycle change event. | 8279| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | Yes | Callback used to return the window stage lifecycle state. | 8280 8281**Error codes** 8282 8283For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8284 8285| ID | Error Message | 8286| ------- | ------------------------------ | 8287| 1300002 | This window state is abnormal. | 8288| 1300005 | This window stage is abnormal. | 8289 8290**Example** 8291 8292```ts 8293import UIAbility from '@ohos.app.ability.UIAbility'; 8294import window from '@ohos.window'; 8295 8296export default class EntryAbility extends UIAbility { 8297 // ... 8298 8299 onWindowStageCreate(windowStage: window.WindowStage) { 8300 console.log('onWindowStageCreate'); 8301 try { 8302 windowStage.on('windowStageEvent', (data) => { 8303 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 8304 JSON.stringify(data)); 8305 }); 8306 } catch (exception) { 8307 console.error('Failed to enable the listener for window stage event changes. Cause:' + 8308 JSON.stringify(exception)); 8309 } 8310 } 8311}; 8312``` 8313 8314### off('windowStageEvent')<sup>9+</sup> 8315 8316off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 8317 8318Unsubscribes from the window stage lifecycle change event. 8319 8320**Model restriction**: This API can be used only in the stage model. 8321 8322**System capability**: SystemCapability.WindowManager.WindowManager.Core 8323 8324**Parameters** 8325 8326| Name | Type | Mandatory | Description | 8327| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 8328| type | string | Yes | Event type. The value is fixed at **'windowStageEvent'**, indicating the window stage lifecycle change event. | 8329| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | No | Callback used to return the window stage lifecycle state. If a value is passed in, the corresponding subscription is canceled. If no value is passed in, all subscriptions to the specified event are canceled. | 8330 8331**Error codes** 8332 8333For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8334 8335| ID | Error Message | 8336| ------- | ------------------------------ | 8337| 1300002 | This window state is abnormal. | 8338| 1300005 | This window stage is abnormal. | 8339 8340**Example** 8341 8342```ts 8343import UIAbility from '@ohos.app.ability.UIAbility'; 8344import window from '@ohos.window'; 8345 8346export default class EntryAbility extends UIAbility { 8347 // ... 8348 8349 onWindowStageCreate(windowStage: window.WindowStage) { 8350 console.log('onWindowStageCreate'); 8351 try { 8352 windowStage.off('windowStageEvent'); 8353 } catch (exception) { 8354 console.error('Failed to disable the listener for window stage event changes. Cause:' + 8355 JSON.stringify(exception)); 8356 } 8357 } 8358}; 8359``` 8360 8361### disableWindowDecor()<sup>9+</sup> 8362 8363disableWindowDecor(): void 8364 8365Disables window decorators. 8366 8367**Model restriction**: This API can be used only in the stage model. 8368 8369**System API**: This is a system API. 8370 8371**System capability**: SystemCapability.WindowManager.WindowManager.Core 8372 8373**Error codes** 8374 8375For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8376 8377| ID | Error Message | 8378| ------- | ------------------------------ | 8379| 1300002 | This window state is abnormal. | 8380| 1300005 | This window stage is abnormal. | 8381 8382**Example** 8383 8384```ts 8385import UIAbility from '@ohos.app.ability.UIAbility'; 8386import window from '@ohos.window'; 8387 8388export default class EntryAbility extends UIAbility { 8389 // ... 8390 8391 onWindowStageCreate(windowStage: window.WindowStage) { 8392 console.log('disableWindowDecor'); 8393 windowStage.disableWindowDecor(); 8394 } 8395}; 8396``` 8397 8398### setShowOnLockScreen()<sup>9+</sup> 8399 8400setShowOnLockScreen(showOnLockScreen: boolean): void 8401 8402Sets whether to display the window of the application on the lock screen. 8403 8404**System API**: This is a system API. 8405 8406**Model restriction**: This API can be used only in the stage model. 8407 8408**System capability**: SystemCapability.WindowManager.WindowManager.Core 8409 8410**Parameters** 8411 8412| Name | Type | Mandatory | Description | 8413| ---------------- | ------- | --------- | ------------------------------------------------------------ | 8414| showOnLockScreen | boolean | Yes | Whether to display the window on the lock screen. The value **true** means to display the window on the lock screen, and **false** means the opposite. | 8415 8416**Error codes** 8417 8418For details about the error codes, see [Window Error Codes](../errorcodes/errorcode-window.md). 8419 8420| ID | Error Message | 8421| ------- | ------------------------------ | 8422| 1300002 | This window state is abnormal. | 8423| 1300005 | This window stage is abnormal. | 8424 8425**Example** 8426 8427```ts 8428import UIAbility from '@ohos.app.ability.UIAbility'; 8429import window from '@ohos.window'; 8430 8431export default class EntryAbility extends UIAbility { 8432 // ... 8433 8434 onWindowStageCreate(windowStage: window.WindowStage) { 8435 console.log('onWindowStageCreate'); 8436 try { 8437 windowStage.setShowOnLockScreen(true); 8438 } catch (exception) { 8439 console.error('Failed to show on lockscreen. Cause:' + JSON.stringify(exception)); 8440 } 8441 } 8442}; 8443``` 8444## TransitionContext<sup>9+</sup> 8445 8446Provides the context for the transition animation. 8447 8448### Attributes 8449 8450**System API**: This is a system API. 8451 8452**System capability**: SystemCapability.WindowManager.WindowManager.Core 8453 8454| Name | Type | Readable | Writable | Description | 8455| --------------------- | ----------------- | -------- | -------- | --------------------------------------- | 8456| toWindow<sup>9+</sup> | [Window](#window) | Yes | Yes | Target window to display the animation. | 8457 8458### completeTransition<sup>9+</sup> 8459 8460completeTransition(isCompleted: boolean): void 8461 8462Completes the transition. This API can be called only after [animateTo()](../arkui-ts/ts-explicit-animation.md) is executed. 8463 8464**System API**: This is a system API. 8465 8466**System capability**: SystemCapability.WindowManager.WindowManager.Core 8467 8468**Parameters** 8469 8470| Name | Type | Mandatory | Description | 8471| ----------- | ------- | --------- | ------------------------------------------------------------ | 8472| isCompleted | boolean | Yes | Whether the transition is complete. The value **true** means that the transition is complete, and **false** means the opposite. | 8473 8474**Example** 8475 8476```ts 8477let windowClass: window.Window | null = null; 8478 8479let controller: window.TransitionController = windowClass.getTransitionController(); 8480controller.animationForShown = (context: window.TransitionContext) => { 8481 let toWindow: window.Window = context.toWindow; 8482 animateTo({ 8483 duration: 1000, // Animation duration. 8484 tempo: 0.5, // Playback speed. 8485 curve: Curve.EaseInOut, // Animation curve. 8486 delay: 0, // Animation delay. 8487 iterations: 1, // Number of playback times. 8488 playMode: PlayMode.Normal // Animation playback mode. 8489 }, () => { 8490 let obj: window.TranslateOptions = { 8491 x: 100.0, 8492 y: 0.0, 8493 z: 0.0 8494 }; 8495 toWindow.translate(obj); 8496 console.info('toWindow translate end'); 8497 } 8498 ); 8499 try { 8500 context.completeTransition(true) 8501 } catch (exception) { 8502 console.info('toWindow translate fail. Cause: ' + JSON.stringify(exception)); 8503 } 8504 console.info('complete transition end'); 8505}; 8506``` 8507 8508## TransitionController<sup>9+</sup> 8509 8510Implements the transition animation controller. 8511 8512### animationForShown<sup>9+</sup> 8513 8514animationForShown(context: TransitionContext): void 8515 8516Customizes the animation for the scenario when the window is shown. 8517 8518**System API**: This is a system API. 8519 8520**System capability**: SystemCapability.WindowManager.WindowManager.Core 8521 8522**Parameters** 8523 8524| Name | Type | Mandatory | Description | 8525| ------- | ---------------------------------------- | --------- | ------------------------------------ | 8526| context | [TransitionContext](#transitioncontext9) | Yes | Context of the transition animation. | 8527 8528**Example** 8529 8530```ts 8531let windowClass: window.Window | null = null; 8532let controller: window.TransitionController = windowClass.getTransitionController(); 8533controller.animationForShown = (context : window.TransitionContext) => { 8534 let toWindow: window.Window = context.toWindow; 8535 animateTo({ 8536 duration: 1000, // Animation duration. 8537 tempo: 0.5, // Playback speed. 8538 curve: Curve.EaseInOut, // Animation curve. 8539 delay: 0, // Animation delay. 8540 iterations: 1, // Number of playback times. 8541 playMode: PlayMode.Normal // Animation playback mode. 8542 onFinish: ()=> { 8543 context.completeTransition(true) 8544 } 8545 }, () => { 8546 let obj : window.TranslateOptions = { 8547 x : 100.0, 8548 y : 0.0, 8549 z : 0.0 8550 }; 8551 toWindow.translate(obj); 8552 console.info('toWindow translate end'); 8553 } 8554 ); 8555 console.info('complete transition end'); 8556}; 8557``` 8558 8559### animationForHidden<sup>9+</sup> 8560 8561animationForHidden(context: TransitionContext): void 8562 8563Customizes the animation for the scenario when the window is hidden. 8564 8565**System API**: This is a system API. 8566 8567**System capability**: SystemCapability.WindowManager.WindowManager.Core 8568 8569**Parameters** 8570 8571| Name | Type | Mandatory | Description | 8572| ------- | ---------------------------------------- | --------- | ------------------------------------ | 8573| context | [TransitionContext](#transitioncontext9) | Yes | Context of the transition animation. | 8574 8575**Example** 8576 8577```ts 8578let windowClass: window.Window | null = null; 8579let controller: window.TransitionController = windowClass.getTransitionController(); 8580controller.animationForHidden = (context: window.TransitionContext) => { 8581 let toWindow: window.Window = context.toWindow; 8582 animateTo({ 8583 duration: 1000, // Animation duration. 8584 tempo: 0.5, // Playback speed. 8585 curve: Curve.EaseInOut, // Animation curve. 8586 delay: 0, // Animation delay. 8587 iterations: 1, // Number of playback times. 8588 playMode: PlayMode.Normal // Animation playback mode. 8589 onFinish: () => { 8590 context.completeTransition(true) 8591 } 8592 }, () => { 8593 let obj: window.TranslateOptions = { 8594 x: 100.0, 8595 y: 0.0, 8596 z: 0.0 8597 }; 8598 toWindow.translate(obj); 8599 console.info('toWindow translate end'); 8600 } 8601 ) 8602 console.info('complete transition end'); 8603}; 8604```