1# @ohos.window (窗口)(系统接口) 2 3窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。 4 5该模块提供以下窗口相关的常用功能: 6 7- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。 8- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。 9 10> **说明:** 11> 12> - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 13> 14> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.window (窗口)](js-apis-window.md)。 15 16## 导入模块 17 18```ts 19import { window } from '@kit.ArkUI'; 20``` 21 22## WindowType<sup>7+</sup> 23 24 25窗口类型枚举。 26 27 28| 名称 | 值 | 说明 | 29|-------------------------------------| ------ |----------------------------------------------------------------------------------------| 30| TYPE_INPUT_METHOD<sup>(deprecated)</sup> | 2 | 表示输入法窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**说明:** 从API version 9开始支持,从API version 13开始废弃,无替代窗口类型,输入法相关控制都请调用[输入法框架侧接口](../../inputmethod/inputmethod-application-guide.md)执行。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 31| TYPE_STATUS_BAR<sup>9+</sup> | 3 | 表示状态栏窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 32| TYPE_PANEL<sup>9+</sup> | 4 | 表示通知栏。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 33| TYPE_KEYGUARD<sup>9+</sup> | 5 | 表示锁屏。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 34| TYPE_VOLUME_OVERLAY<sup>9+</sup> | 6 | 表示音量条。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 35| TYPE_NAVIGATION_BAR<sup>9+</sup> | 7 | 表示导航栏窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 36| TYPE_WALLPAPER<sup>9+</sup> | 9 | 表示壁纸。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 37| TYPE_DESKTOP<sup>9+</sup> | 10 | 表示桌面。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 38| TYPE_LAUNCHER_RECENT<sup>9+</sup> | 11 | 表示多任务中心。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 39| TYPE_LAUNCHER_DOCK<sup>9+</sup> | 12 | 表示桌面Dock栏。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 40| TYPE_VOICE_INTERACTION<sup>9+</sup> | 13 | 表示智慧语音。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 41| TYPE_POINTER<sup>9+</sup> | 14 | 表示鼠标。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 42| TYPE_FLOAT_CAMERA<sup>9+</sup> | 15 | 表示相机类型悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 43| TYPE_SCREENSHOT<sup>9+</sup> | 17 | 表示截屏窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 44| TYPE_SYSTEM_TOAST<sup>11+</sup> | 18 | 表示顶层提示窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 45| TYPE_DIVIDER<sup>11+</sup> | 19 | 表示分屏条。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 46| TYPE_GLOBAL_SEARCH<sup>11+</sup> | 20 | 表示全局搜索窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.WindowManager.WindowManager.Core | 47| TYPE_HANDWRITE<sup>12+</sup> | 21 | 表示手写笔窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。<br>**系统能力:** SystemCapability.Window.SessionManager | 48 49## WindowMode<sup>7+</sup> 50 51窗口模式枚举。 52 53**系统接口:** 此接口为系统接口。 54 55**系统能力:** SystemCapability.WindowManager.WindowManager.Core 56 57| 名称 | 值 | 说明 | 58| ---------- | ---- | ----------------------------- | 59| UNDEFINED | 1 | 表示APP未定义窗口模式。 | 60| FULLSCREEN | 2 | 表示APP全屏模式。 | 61| PRIMARY | 3 | 表示APP分屏多窗口主要模式。 | 62| SECONDARY | 4 | 表示APP分屏多窗口次要模式。 | 63| FLOATING | 5 | 表示APP自由悬浮形式窗口模式。 | 64 65## WindowLayoutMode<sup>9+</sup> 66 67窗口布局模式枚举。 68 69**系统接口:** 此接口为系统接口。 70 71**系统能力:** SystemCapability.WindowManager.WindowManager.Core 72 73| 名称 | 值 | 说明 | 74| ---------- | ---- | ----------------------------- | 75| WINDOW_LAYOUT_MODE_CASCADE | 0 | 表示使用层叠布局模式。 | 76| WINDOW_LAYOUT_MODE_TILE | 1 | 表示使用平铺布局模式。 | 77 78 79## BlurStyle<sup>9+</sup> 80 81窗口模糊类型枚举。 82 83**系统接口:** 此接口为系统接口。 84 85**系统能力:** SystemCapability.WindowManager.WindowManager.Core 86 87| 名称 | 值 | 说明 | 88| ------- | ---- | -------------------- | 89| OFF | 0 | 表示关闭模糊。 | 90| THIN | 1 | 表示较薄的模糊类型。 | 91| REGULAR | 2 | 表示适中的模糊类型。 | 92| THICK | 3 | 表示较厚的模糊类型。 | 93 94## SystemBarRegionTint<sup>8+</sup> 95 96单个导航栏或状态栏回调信息。 97 98**系统接口:** 此接口为系统接口。 99 100**系统能力:** SystemCapability.WindowManager.WindowManager.Core 101 102| 名称 | 类型 | 可读 | 可写 | 说明 | 103| --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | 104| type | [WindowType](#windowtype7) | 是 | 否 | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 | 105| isEnable | boolean | 是 | 否 | 当前系统栏是否显示。true表示显示;false表示不显示。 | 106| region | [Rect](js-apis-window.md#rect7) | 是 | 否 | 当前系统栏的位置及大小。 | 107| backgroundColor | string | 是 | 否 | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 108| contentColor | string | 是 | 否 | 系统栏文字颜色。 | 109 110## SystemBarTintState<sup>8+</sup> 111 112当前系统栏回调信息集合。 113 114**系统接口:** 此接口为系统接口。 115 116**系统能力:** SystemCapability.WindowManager.WindowManager.Core 117 118| 名称 | 类型 | 可读 | 可写 | 说明 | 119| ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- | 120| displayId | number | 是 | 否 | 当前物理屏幕id,该参数应为整数。 | 121| regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | 否 | 当前已改变的所有系统栏信息。 | 122 123## ScaleOptions<sup>9+</sup> 124 125缩放参数。 126 127**系统接口:** 此接口为系统接口。 128 129**系统能力**:SystemCapability.WindowManager.WindowManager.Core 130 131| 名称 | 类型 | 只读 | 必填 | 说明 | 132| ------ | -------- | ---- | ---- | --------------------------------------------| 133| x | number | 否 | 否 | X轴的缩放参数。该参数为浮点数,默认值为1.0。 | 134| y | number | 否 | 否 | Y轴的缩放参数。该参数为浮点数,默认值为1.0。 | 135| pivotX | number | 否 | 否 | 缩放中心点X轴坐标。该参数为浮点数,默认值为0.5, 取值范围[0.0, 1.0]。 | 136| pivotY | number | 否 | 否 | 缩放中心点Y轴坐标。该参数为浮点数,默认值为0.5, 取值范围[0.0, 1.0]。 | 137 138## RotateOptions<sup>9+</sup> 139 140旋转参数。 141 142**系统接口:** 此接口为系统接口。 143 144**系统能力**:SystemCapability.WindowManager.WindowManager.Core 145 146| 名称 | 类型 | 只读 | 必填 | 说明 | 147| ------ | -------- | ---- |---- |---------------------------------------------| 148| x | number | 否 | 否 | 绕X轴的旋转角度。该参数为浮点数,默认值为0.0。 | 149| y | number | 否 | 否 | 绕Y轴的旋转角度。该参数为浮点数,默认值为0.0。 | 150| z | number | 否 | 否 | 绕Z轴的旋转角度。该参数为浮点数,默认值为0.0。 | 151| pivotX | number | 否 | 否 | 旋转中心点X轴坐标。该参数为浮点数,默认值为0.5, 取值范围为[0.0, 1.0]。 | 152| pivotY | number | 否 | 否 | 旋转中心点Y轴坐标。该参数为浮点数,默认值为0.5, 取值范围为[0.0, 1.0]。 | 153 154## TranslateOptions<sup>9+</sup> 155 156平移参数。 157 158**系统接口:** 此接口为系统接口。 159 160**系统能力**:SystemCapability.WindowManager.WindowManager.Core 161 162| 名称 | 类型 | 只读 | 可选 | 说明 | 163| ---- | -------- | ---- | ---- | ---------------------------- | 164| x | number | 否 | 是 | X轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | 165| y | number | 否 | 是 | Y轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | 166| z | number | 否 | 是 | Z轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | 167 168## WindowInfo<sup>12+</sup> 169 170当前窗口的详细信息。 171 172**系统接口:** 此接口为系统接口。 173 174**系统能力:** SystemCapability.Window.SessionManager 175 176| 名称 | 类型 | 只读 | 可选 | 说明 | 177| ------ | ------ | ---- | ---- | ------------------------------------------ | 178| rect | [Rect](js-apis-window.md#rect7) | 是 | 否 | 窗口内可绘制区域尺寸,其中左边界上边界是相对窗口计算。 | 179| bundleName | string | 是 | 否 | 应用Bundle的名称。 | 180| abilityName | string | 是 | 否 | Ability的名称。 | 181| windowId | number | 是 | 否 | 窗口ID。 | 182| windowStatusType | [WindowStatusType](js-apis-window.md#windowstatustype11) | 是 | 否 | 窗口模式枚举。 | 183| isFocused<sup>14+</sup> | boolean | 是 | 是 | 窗口是否获焦。true表示窗口获焦;false表示窗口未获焦。 | 184 185## window.minimizeAll<sup>9+</sup> 186minimizeAll(id: number, callback: AsyncCallback<void>): void 187 188最小化某显示设备下的所有窗口。 189 190**系统接口:** 此接口为系统接口。 191 192**系统能力:** SystemCapability.WindowManager.WindowManager.Core 193 194**参数:** 195 196| 参数名 | 类型 | 必填 | 说明 | 197| -------- | ------------------------- | ---- | -------------- | 198| id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号,该参数仅支持整数输入。 | 199| callback | AsyncCallback<void> | 是 | 回调信息。 | 200 201**错误码:** 202 203以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 204 205| 错误码ID | 错误信息 | 206| ------- | -------------------------------------------- | 207| 202 | Permission verification failed. A non-system application calls a system API. | 208| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 209| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 210| 1300003 | This window manager service works abnormally. | 211 212**示例:** 213 214```ts 215import { display } from '@kit.ArkUI'; 216import { BusinessError } from '@kit.BasicServicesKit'; 217 218let displayClass: display.Display | null = null; 219displayClass = display.getDefaultDisplaySync(); 220 221try { 222 window.minimizeAll(displayClass.id, (err: BusinessError) => { 223 const errCode: number = err.code; 224 if (errCode) { 225 console.error(`Failed to minimize all windows. Cause code: ${err.code}, message: ${err.message}`); 226 return; 227 } 228 console.info('Succeeded in minimizing all windows.'); 229 }); 230} catch (exception) { 231 console.error(`Failed to minimize all windows. Cause code: ${exception.code}, message: ${exception.message}`); 232} 233``` 234 235## window.minimizeAll<sup>9+</sup> 236minimizeAll(id: number): Promise<void> 237 238最小化某显示设备下的所有窗口。 239 240**系统接口:** 此接口为系统接口。 241 242**系统能力:** SystemCapability.WindowManager.WindowManager.Core 243 244**参数:** 245 246| 参数名 | 类型 | 必填 | 说明 | 247| -------- | ------------------------- | ---- | -------------- | 248| id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号,该参数仅支持整数输入。 | 249 250**返回值:** 251 252| 类型 | 说明 | 253| ------------------- | ------------------------- | 254| Promise<void> | 无返回结果的Promise对象。 | 255 256**错误码:** 257 258以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 259 260| 错误码ID | 错误信息 | 261| ------- | -------------------------------------------- | 262| 202 | Permission verification failed. A non-system application calls a system API. | 263| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 264| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 265| 1300003 | This window manager service works abnormally. | 266 267**示例:** 268 269```ts 270import { display } from '@kit.ArkUI'; 271import { BusinessError } from '@kit.BasicServicesKit'; 272 273let displayClass: display.Display | null = null; 274displayClass = display.getDefaultDisplaySync(); 275 276try { 277 let promise = window.minimizeAll(displayClass.id); 278 promise.then(() => { 279 console.info('Succeeded in minimizing all windows.'); 280 }).catch((err: BusinessError) => { 281 console.error(`Failed to minimize all windows. Cause code: ${err.code}, message: ${err.message}`); 282 }); 283} catch (exception) { 284 console.error(`Failed to minimize all windows. Cause code: ${exception.code}, message: ${exception.message}`); 285} 286``` 287 288## window.toggleShownStateForAllAppWindows<sup>9+</sup> 289toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void 290 291多窗口快速切换时隐藏或者恢复应用窗口。 292 293**系统接口:** 此接口为系统接口。 294 295**系统能力:** SystemCapability.WindowManager.WindowManager.Core 296 297**参数:** 298 299| 参数名 | 类型 | 必填 | 说明 | 300| -------- | ------------------------- | ---- | -------------- | 301| callback | AsyncCallback<void> | 是 | 回调信息。 | 302 303**错误码:** 304 305以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 306 307| 错误码ID | 错误信息 | 308| ------- | -------------------------------------------- | 309| 202 | Permission verification failed. A non-system application calls a system API. | 310| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 311| 1300003 | This window manager service works abnormally. | 312 313**示例:** 314 315```ts 316import { BusinessError } from '@kit.BasicServicesKit'; 317 318window.toggleShownStateForAllAppWindows((err: BusinessError) => { 319 const errCode: number = err.code; 320 if (errCode) { 321 console.error(`Failed to toggle shown state for all app windows. Cause code: ${err.code}, message: ${err.message}`); 322 return; 323 } 324 console.info('Succeeded in toggling shown state for all app windows.'); 325}); 326``` 327 328## window.toggleShownStateForAllAppWindows<sup>9+</sup> 329toggleShownStateForAllAppWindows(): Promise<void> 330 331多窗口快速切换时隐藏或者恢复应用窗口。 332 333**系统接口:** 此接口为系统接口。 334 335**系统能力:** SystemCapability.WindowManager.WindowManager.Core 336 337**返回值:** 338 339| 类型 | 说明 | 340| ------------------- | ------------------------- | 341| Promise<void> | 无返回结果的Promise对象。 | 342 343**错误码:** 344 345以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 346 347| 错误码ID | 错误信息 | 348| ------- | -------------------------------------------- | 349| 202 | Permission verification failed. A non-system application calls a system API. | 350| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 351| 1300003 | This window manager service works abnormally. | 352 353**示例:** 354 355```ts 356import { BusinessError } from '@kit.BasicServicesKit'; 357 358let promise = window.toggleShownStateForAllAppWindows(); 359promise.then(() => { 360 console.info('Succeeded in toggling shown state for all app windows.'); 361}).catch((err: BusinessError) => { 362 console.error(`Failed to toggle shown state for all app windows. Cause code: ${err.code}, message: ${err.message}`); 363}); 364``` 365 366## window.setWindowLayoutMode<sup>9+</sup> 367setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void 368 369设置窗口布局模式。 370 371**系统接口:** 此接口为系统接口。 372 373**系统能力:** SystemCapability.WindowManager.WindowManager.Core 374 375**参数:** 376 377| 参数名 | 类型 | 必填 | 说明 | 378| -------- | ------------------------- | ---- | -------------- | 379| mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | 380| callback | AsyncCallback<void> | 是 | 回调信息。 | 381 382**错误码:** 383 384以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 385 386| 错误码ID | 错误信息 | 387| ------- | -------------------------------------------- | 388| 202 | Permission verification failed. A non-system application calls a system API. | 389| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 390| 1300003 | This window manager service works abnormally. | 391 392**示例:** 393 394```ts 395import { BusinessError } from '@kit.BasicServicesKit'; 396 397try { 398 window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (err: BusinessError) => { 399 const errCode: number = err.code; 400 if (errCode) { 401 console.error(`Failed to set window layout mode. Cause code: ${err.code}, message: ${err.message}`); 402 return; 403 } 404 console.info('Succeeded in setting window layout mode.'); 405 }); 406} catch (exception) { 407 console.error(`Failed to set window layout mode. Cause code: ${exception.code}, message: ${exception.message}`); 408} 409``` 410 411## window.setWindowLayoutMode<sup>9+</sup> 412setWindowLayoutMode(mode: WindowLayoutMode): Promise<void> 413 414设置窗口布局模式。 415 416**系统接口:** 此接口为系统接口。 417 418**系统能力:** SystemCapability.WindowManager.WindowManager.Core 419 420**参数:** 421 422| 参数名 | 类型 | 必填 | 说明 | 423| -------- | ------------------------- | ---- | -------------- | 424| mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | 425 426**返回值:** 427 428| 类型 | 说明 | 429| ------------------- | ------------------------- | 430| Promise<void> | 无返回结果的Promise对象。 | 431 432**错误码:** 433 434以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 435 436| 错误码ID | 错误信息 | 437| ------- | -------------------------------------------- | 438| 202 | Permission verification failed. A non-system application calls a system API. | 439| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 440| 1300003 | This window manager service works abnormally. | 441 442**示例:** 443 444```ts 445import { BusinessError } from '@kit.BasicServicesKit'; 446 447try { 448 let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE); 449 promise.then(() => { 450 console.info('Succeeded in setting window layout mode.'); 451 }).catch((err: BusinessError) => { 452 console.error(`Failed to set window layout mode. Cause code: ${err.code}, message: ${err.message}`); 453 }); 454} catch (exception) { 455 console.error(`Failed to set window layout mode. Cause code: ${exception.code}, message: ${exception.message}`); 456} 457``` 458 459## window.on('systemBarTintChange')<sup>8+</sup> 460 461on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void 462 463开启状态栏、导航栏属性变化的监听。 464 465**系统接口:** 此接口为系统接口。 466 467**系统能力:** SystemCapability.WindowManager.WindowManager.Core 468 469**参数:** 470 471| 参数名 | 类型 | 必填 | 说明 | 472| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 473| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | 474| callback | Callback<[SystemBarTintState](#systembartintstate8)> | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 | 475 476**错误码:** 477 478以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 479 480| 错误码ID | 错误信息 | 481| ------- | -------------------------------- | 482| 202 | Permission verification failed. A non-system application calls a system API. | 483| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 484 485**示例:** 486 487```ts 488try { 489 window.on('systemBarTintChange', (data) => { 490 console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data)); 491 }); 492} catch (exception) { 493 console.error(`Failed to enable the listener for systemBarTint changes. Cause code: ${exception.code}, message: ${exception.message}`); 494} 495``` 496 497## window.off('systemBarTintChange')<sup>8+</sup> 498 499off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void 500 501关闭状态栏、导航栏属性变化的监听。 502 503**系统接口:** 此接口为系统接口。 504 505**系统能力:** SystemCapability.WindowManager.WindowManager.Core 506 507**参数:** 508 509| 参数名 | 类型 | 必填 | 说明 | 510| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 511| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | 512| callback | Callback<[SystemBarTintState](#systembartintstate8)> | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有状态栏、导航栏属性变化的监听。 | 513 514**错误码:** 515 516以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 517 518| 错误码ID | 错误信息 | 519| ------- | -------------------------------- | 520| 202 | Permission verification failed. A non-system application calls a system API. | 521| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 522 523**示例:** 524 525```ts 526const callback = (systemBarTintState: window.SystemBarTintState) => { 527 // ... 528} 529try { 530 window.on('systemBarTintChange', callback); 531 532 window.off('systemBarTintChange', callback); 533 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 534 window.off('systemBarTintChange'); 535} catch (exception) { 536 console.error(`Failed to enable or disable the listener for systemBarTint changes. Cause code: ${exception.code}, message: ${exception.message}`); 537} 538``` 539 540## window.on('gestureNavigationEnabledChange')<sup>10+</sup> 541 542on(type: 'gestureNavigationEnabledChange', callback: Callback<boolean>): void 543 544添加手势导航启用状态变化的监听。 545 546**系统接口:** 此接口为系统接口。 547 548**系统能力:** SystemCapability.WindowManager.WindowManager.Core 549 550**参数:** 551 552| 参数名 | 类型 | 必填 | 说明 | 553| -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | 554| type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 | 555| callback | Callback<boolean> | 是 | 回调函数。返回当前手势导航的启用状态。true表示手势导航状态变化为启用;false表示手势导航状态变化为禁用。 | 556 557**错误码:** 558 559以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 560 561| 错误码ID | 错误信息 | 562| ------- | -------------------------------------------- | 563| 202 | Permission verification failed. A non-system application calls a system API. | 564| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 565| 1300002 | This window state is abnormal. | 566| 1300003 | This window manager service works abnormally. | 567 568**示例:** 569 570```ts 571try { 572 window.on('gestureNavigationEnabledChange', (data) => { 573 console.info('Succeeded in enabling the listener for gesture navigation status changes. Data: ' + JSON.stringify(data)); 574 }); 575} catch (exception) { 576 console.error(`Failed to enable the listener for gesture navigation status changes. Cause code: ${exception.code}, message: ${exception.message}`); 577} 578``` 579 580## window.off('gestureNavigationEnabledChange')<sup>10+</sup> 581 582off(type: 'gestureNavigationEnabledChange', callback?: Callback<boolean>): void 583 584移除手势导航启用状态变化的监听。 585 586**系统接口:** 此接口为系统接口。 587 588**系统能力:** SystemCapability.WindowManager.WindowManager.Core 589 590**参数:** 591 592| 参数名 | 类型 | 必填 | 说明 | 593| -------- | ----------------------- | -- | ------------------------------------------------------------ | 594| type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 | 595| callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有手势导航启用状态变化的监听。 | 596 597**错误码:** 598 599以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 600 601| 错误码ID | 错误信息 | 602| ------- | -------------------------------------------- | 603| 202 | Permission verification failed. A non-system application calls a system API. | 604| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 605| 1300002 | This window state is abnormal. | 606| 1300003 | This window manager service works abnormally. | 607 608**示例:** 609 610```ts 611const callback = (bool: boolean) => { 612 // ... 613} 614try { 615 window.on('gestureNavigationEnabledChange', callback); 616 window.off('gestureNavigationEnabledChange', callback); 617 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 618 window.off('gestureNavigationEnabledChange'); 619} catch (exception) { 620 console.error(`Failed to enable or disable the listener for gesture navigation status changes. Cause code: ${exception.code}, message: ${exception.message}`); 621} 622``` 623 624## window.on('waterMarkFlagChange')<sup>10+</sup> 625 626on(type: 'waterMarkFlagChange', callback: Callback<boolean>): void 627 628添加水印启用状态变化的监听。 629 630**系统接口:** 此接口为系统接口。 631 632**系统能力:** SystemCapability.WindowManager.WindowManager.Core 633 634**参数:** 635 636| 参数名 | 类型 | 必填 | 说明 | 637| -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | 638| type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 | 639| callback | Callback<boolean> | 是 | 回调函数。返回当前水印的启用状态。true表示当前已启用水印;false表示当前未启用水印。 | 640 641**错误码:** 642 643以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 644 645| 错误码ID | 错误信息 | 646| ------- | -------------------------------------------- | 647| 202 | Permission verification failed. A non-system application calls a system API. | 648| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 649| 1300003 | This window manager service works abnormally. | 650 651**示例:** 652 653```ts 654try { 655 window.on('waterMarkFlagChange', (data) => { 656 console.info('Succeeded in enabling the listener for watermark flag changes. Data: ' + JSON.stringify(data)); 657 }); 658} catch (exception) { 659 console.error(`Failed to enable the listener for watermark flag changes. Cause code: ${exception.code}, message: ${exception.message}`); 660} 661``` 662 663## window.off('waterMarkFlagChange')<sup>10+</sup> 664 665off(type: 'waterMarkFlagChange', callback?: Callback<boolean>): void 666 667移除水印启用状态变化的监听。 668 669**系统接口:** 此接口为系统接口。 670 671**系统能力:** SystemCapability.WindowManager.WindowManager.Core 672 673**参数:** 674 675| 参数名 | 类型 | 必填 | 说明 | 676| -------- | ----------------------- | -- | ------------------------------------------------------------ | 677| type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 | 678| callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有水印启用状态变化的监听。 | 679 680**错误码:** 681 682以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 683 684| 错误码ID | 错误信息 | 685| ------- | -------------------------------------------- | 686| 202 | Permission verification failed. A non-system application calls a system API. | 687| 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | 688| 1300003 | This window manager service works abnormally. | 689 690**示例:** 691 692```ts 693const callback = (bool: boolean) => { 694 // ... 695} 696try { 697 window.on('waterMarkFlagChange', callback); 698 window.off('waterMarkFlagChange', callback); 699 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 700 window.off('waterMarkFlagChange'); 701} catch (exception) { 702 console.error(`Failed to enable or disable the listener for watermark flag changes. Cause code: ${exception.code}, message: ${exception.message}`); 703} 704``` 705 706## window.setGestureNavigationEnabled<sup>10+</sup> 707setGestureNavigationEnabled(enable: boolean, callback: AsyncCallback<void>): void 708 709设置手势导航启用状态。使用callback异步回调。系统出于安全的考虑,不会干预手势的禁用和恢复。应用调用本接口禁用手势后异常退出的情况下,如果想要恢复手势,需自行实现自动拉起机制并再次调用本接口恢复手势。 710 711**系统接口:** 此接口为系统接口。 712 713**系统能力:** SystemCapability.WindowManager.WindowManager.Core 714 715**参数:** 716 717| 参数名 | 类型 | 必填 | 说明 | 718| -------- | ------------------------- | ---- | -------------- | 719| enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 | 720| callback | AsyncCallback<void> | 是 | 回调信息。 | 721 722**错误码:** 723 724以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 725 726| 错误码ID | 错误信息 | 727| ------- | --------------------------------------------- | 728| 202 | Permission verification failed. A non-system application calls a system API. | 729| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 730| 1300002 | This window state is abnormal. | 731| 1300003 | This window manager service works abnormally. | 732 733**示例:** 734 735```ts 736import { BusinessError } from '@kit.BasicServicesKit'; 737 738try { 739 window.setGestureNavigationEnabled(true, (err: BusinessError) => { 740 const errCode: number = err.code; 741 if (errCode) { 742 console.error(`Failed to set gesture navigation enabled. Cause code: ${err.code}, message: ${err.message}`); 743 return; 744 } 745 console.info('Succeeded in setting gesture navigation enabled.'); 746 }); 747} catch (exception) { 748 console.error(`Failed to set gesture navigation enabled. Cause code: ${exception.code}, message: ${exception.message}`); 749} 750``` 751 752## window.setGestureNavigationEnabled<sup>10+</sup> 753setGestureNavigationEnabled(enable: boolean): Promise<void> 754 755设置手势导航启用状态。使用Promise异步回调。系统出于安全的考虑,不会干预手势的禁用和恢复。应用调用本接口禁用手势后异常退出的情况下,如果想要恢复手势,需自行实现自动拉起机制并再次调用本接口恢复手势。 756 757**系统接口:** 此接口为系统接口。 758 759**系统能力:** SystemCapability.WindowManager.WindowManager.Core 760 761**参数:** 762 763| 参数名 | 类型 | 必填 | 说明 | 764| ------ | ------- | ---- | -------------------- | 765| enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 | 766 767**返回值:** 768 769| 类型 | 说明 | 770| ------------------- | ------------------------- | 771| Promise<void> | 无返回结果的Promise对象。 | 772 773**错误码:** 774 775以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 776 777| 错误码ID | 错误信息 | 778| ------- | -------------------------------------------- | 779| 202 | Permission verification failed. A non-system application calls a system API. | 780| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 781| 1300002 | This window state is abnormal. | 782| 1300003 | This window manager service works abnormally. | 783 784**示例:** 785 786```ts 787import { BusinessError } from '@kit.BasicServicesKit'; 788 789try { 790 let promise = window.setGestureNavigationEnabled(true); 791 promise.then(() => { 792 console.info('Succeeded in setting gesture navigation enabled.'); 793 }).catch((err: BusinessError) => { 794 console.error(`Failed to set gesture navigation enabled. Cause code: ${err.code}, message: ${err.message}`); 795 }); 796} catch (exception) { 797 console.error(`Failed to set gesture navigation enabled. Cause code: ${exception.code}, message: ${exception.message}`); 798} 799``` 800 801## window.setWaterMarkImage<sup>10+</sup> 802setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean, callback: AsyncCallback<void>): void 803 804设置水印图片显示状态。使用callback异步回调。 805 806**系统接口:** 此接口为系统接口。 807 808**系统能力:** SystemCapability.WindowManager.WindowManager.Core 809 810**参数:** 811 812| 参数名 | 类型 | 必填 | 说明 | 813| -------- | ------------------------- | ---- | -------------- | 814| pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 水印图片。 | 815| enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 | 816| callback | AsyncCallback<void> | 是 | 回调信息。 | 817 818**错误码:** 819 820以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 821 822| 错误码ID | 错误信息 | 823| ------- | --------------------------------------------- | 824| 202 | Permission verification failed. A non-system application calls a system API. | 825| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 826| 1300003 | This window manager service works abnormally. | 827 828**示例:** 829 830```ts 831import { image } from '@kit.ImageKit'; 832import { BusinessError } from '@kit.BasicServicesKit'; 833 834let enable: boolean = true; 835let color: ArrayBuffer = new ArrayBuffer(0); 836let initializationOptions: image.InitializationOptions = { 837 size: { 838 height: 100, 839 width: 100 840 } 841}; 842image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { 843 console.info('Succeeded in creating pixelmap.'); 844 try { 845 window.setWaterMarkImage(pixelMap, enable, (err: BusinessError) => { 846 const errCode: number = err.code; 847 if (errCode) { 848 console.error(`Failed to show watermark image. Cause code: ${err.code}, message: ${err.message}`); 849 return; 850 } 851 console.info('Succeeded in showing watermark image.'); 852 }); 853 } catch (exception) { 854 console.error(`Failed to show watermark image. Cause code: ${exception.code}, message: ${exception.message}`); 855 } 856}).catch((err: BusinessError) => { 857 console.error(`Failed to create PixelMap. Cause code: ${err.code}, message: ${err.message}`); 858}); 859``` 860 861## window.setWaterMarkImage<sup>10+</sup> 862setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean): Promise<void> 863 864设置水印图片显示状态。使用Promise异步回调。 865 866**系统接口:** 此接口为系统接口。 867 868**系统能力:** SystemCapability.WindowManager.WindowManager.Core 869 870**参数:** 871 872| 参数名 | 类型 | 必填 | 说明 | 873| ------ | --------------------------- | ---- | -------------------- | 874| pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 水印图片。 | 875| enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 | 876 877**返回值:** 878 879| 类型 | 说明 | 880| ------------------- | ------------------------- | 881| Promise<void> | 无返回结果的Promise对象。 | 882 883**错误码:** 884 885以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 886 887| 错误码ID | 错误信息 | 888| ------- | -------------------------------------------- | 889| 202 | Permission verification failed. A non-system application calls a system API. | 890| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 891| 1300003 | This window manager service works abnormally. | 892 893**示例:** 894 895```ts 896import { image } from '@kit.ImageKit'; 897import { BusinessError } from '@kit.BasicServicesKit'; 898 899let enable: boolean = true; 900let color: ArrayBuffer = new ArrayBuffer(0); 901let initializationOptions: image.InitializationOptions = { 902 size: { 903 height: 100, 904 width: 100 905 } 906}; 907image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { 908 console.info('Succeeded in creating pixelmap.'); 909 try { 910 let promise = window.setWaterMarkImage(pixelMap, enable); 911 promise.then(() => { 912 console.info('Succeeded in showing watermark image.'); 913 }).catch((err: BusinessError) => { 914 console.error(`Failed to show watermark image. Cause code: ${err.code}, message: ${err.message}`); 915 }); 916 } catch (exception) { 917 console.error(`Failed to show watermark image. Cause code: ${exception.code}, message: ${exception.message}`); 918 } 919}).catch((err: BusinessError) => { 920 console.error(`Failed to create PixelMap. Cause code: ${err.code}, message: ${err.message}`); 921}); 922``` 923 924## window.getSnapshot<sup>12+</sup> 925 926getSnapshot(windowId: number): Promise<image.PixelMap> 927 928获取指定窗口相同尺寸截图,使用Promise异步回调。 929 930**系统接口:** 此接口为系统接口。 931 932**系统能力:** SystemCapability.WindowManager.WindowManager.Core 933 934**参数:** 935| 参数名 | 类型 | 必填 | 说明 | 936| -------- | ------ | ----- | ------------ | 937| windowId | number | 是 | 窗口Id。可通过[getWindowProperties](js-apis-window.md#getwindowproperties9)接口获取到相关窗口属性,其中属性id即对应为窗口ID。 | 938 939**返回值:** 940| 类型 | 说明 | 941| ----------------------- | ------------------------------- | 942| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise对象。返回指定窗口截图。 | 943 944**错误码:** 945以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 946 947| 错误码ID | 错误信息 | 948| -------- | -------------------------------------------- | 949| 202 | Permission verification failed. A non-system application calls a system API. | 950| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 951| 1300002 | This window state is abnormal. | 952| 1300003 | This window manager service works abnormally. | 953| 1300004 | This operation is not accessible. | 954 955**示例:** 956```ts 957import { BusinessError } from '@kit.BasicServicesKit'; 958import { image } from '@kit.ImageKit'; 959 960try { 961 // 此处仅示意,请使用getWindowProperties获取对应窗口ID再进行使用 962 let windowId: number = 40; 963 let promise = window.getSnapshot(windowId); 964 promise.then((pixelMap: image.PixelMap) => { 965 console.info('Succeeded in getting snapshot window. Pixel bytes number:' + pixelMap.getPixelBytesNumber()); 966 pixelMap.release(); 967 }).catch((err: BusinessError) =>{ 968 console.error(`Failed to get snapshot. Cause code: ${err.code}, message: ${err.message}`); 969 }); 970} catch (exception) { 971 console.error(`Failed to get snapshot. Cause code: ${exception.code}, message: ${exception.message}`); 972} 973``` 974 975## window.getVisibleWindowInfo<sup>12+</sup> 976 977getVisibleWindowInfo(): Promise<Array<WindowInfo>> 978 979获取当前屏幕的可见窗口(未退至后台的窗口)信息。 980 981**系统接口:** 此接口为系统接口。 982 983**系统能力:** SystemCapability.Window.SessionManager 984 985 986**返回值:** 987 988| 类型 | 说明 | 989| ------------------- | ----------------------- | 990| Promise<[WindowInfo](#windowinfo12)> | Promise对象,返回当前可见窗口的相关信息。 | 991 992**错误码:** 993 994以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 995 996| 错误码ID | 错误信息 | 997| ------- | ------------------------------ | 998| 202 | Permission verification failed, non-system application uses system API. | 999| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 1000| 1300003 | This window manager service works abnormally. | 1001 1002**示例:** 1003 1004```ts 1005import { window } from '@kit.ArkUI'; 1006import { BusinessError } from '@kit.BasicServicesKit'; 1007 1008let promise = window.getVisibleWindowInfo(); 1009promise.then((data) => { 1010 data.forEach(windowInfo=>{ 1011 console.info(`left:${windowInfo.rect.left}`); 1012 console.info(`top:${windowInfo.rect.top}`); 1013 console.info(`width:${windowInfo.rect.width}`); 1014 console.info(`height:${windowInfo.rect.height}`); 1015 console.info(`windowId:${windowInfo.windowId}`); 1016 console.info(`windowStatusType:${windowInfo.windowStatusType}`); 1017 console.info(`abilityName:${windowInfo.abilityName}`); 1018 console.info(`bundleName:${windowInfo.bundleName}`); 1019 console.info(`isFocused:${windowInfo.isFocused}`); 1020 }) 1021}).catch((err: BusinessError) => { 1022 console.error('Failed to getWindowInfo. Cause: ' + JSON.stringify(err)); 1023}); 1024``` 1025 1026## Window 1027 1028当前窗口实例,窗口管理器管理的基本单元。 1029 1030下列API示例中都需先使用[getLastWindow()](js-apis-window.md#windowgetlastwindow9)、[createWindow()](js-apis-window.md#windowcreatewindow9)、[findWindow()](js-apis-window.md#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。 1031 1032### hide<sup>7+</sup> 1033 1034hide (callback: AsyncCallback<void>): void 1035 1036隐藏当前窗口,使用callback异步回调,仅支持系统窗口与应用子窗口。 1037 1038**系统接口:** 此接口为系统接口。 1039 1040**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1041 1042**参数:** 1043 1044| 参数名 | 类型 | 必填 | 说明 | 1045| -------- | ------------------------- | ---- | ---------- | 1046| callback | AsyncCallback<void> | 是 | 回调函数。 | 1047 1048**错误码:** 1049 1050以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1051 1052| 错误码ID | 错误信息 | 1053| ------- | ------------------------------ | 1054| 202 | Permission verification failed. A non-system application calls a system API. | 1055| 1300002 | This window state is abnormal. | 1056 1057**示例:** 1058 1059```ts 1060import { BusinessError } from '@kit.BasicServicesKit'; 1061 1062windowClass.hide((err: BusinessError) => { 1063 const errCode: number = err.code; 1064 if (errCode) { 1065 console.error(`Failed to hide the window. Cause code: ${err.code}, message: ${err.message}`); 1066 return; 1067 } 1068 console.info('Succeeded in hiding the window.'); 1069}); 1070``` 1071 1072### hide<sup>7+</sup> 1073 1074hide(): Promise<void> 1075 1076隐藏当前窗口,使用Promise异步回调,仅支持系统窗口与应用子窗口。 1077 1078**系统接口:** 此接口为系统接口。 1079 1080**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1081 1082**返回值:** 1083 1084| 类型 | 说明 | 1085| ------------------- | ------------------------- | 1086| Promise<void> | 无返回结果的Promise对象。 | 1087 1088**错误码:** 1089 1090以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1091 1092| 错误码ID | 错误信息 | 1093| ------- | ------------------------------ | 1094| 202 | Permission verification failed. A non-system application calls a system API. | 1095| 1300002 | This window state is abnormal. | 1096 1097**示例:** 1098 1099```ts 1100import { BusinessError } from '@kit.BasicServicesKit'; 1101 1102let promise = windowClass.hide(); 1103promise.then(() => { 1104 console.info('Succeeded in hiding the window.'); 1105}).catch((err: BusinessError) => { 1106 console.error(`Failed to hide the window. Cause code: ${err.code}, message: ${err.message}`); 1107}); 1108``` 1109 1110### hideWithAnimation<sup>9+</sup> 1111 1112hideWithAnimation(callback: AsyncCallback<void>): void 1113 1114隐藏当前窗口,过程中播放动画,使用callback异步回调,仅支持系统窗口。 1115 1116**系统接口:** 此接口为系统接口。 1117 1118**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1119 1120**参数:** 1121 1122| 参数名 | 类型 | 必填 | 说明 | 1123| -------- | ------------------------- | ---- | ---------- | 1124| callback | AsyncCallback<void> | 是 | 回调函数。 | 1125 1126**错误码:** 1127 1128以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1129 1130| 错误码ID | 错误信息 | 1131| ------- | -------------------------------------------- | 1132| 202 | Permission verification failed. A non-system application calls a system API. | 1133| 1300002 | This window state is abnormal. | 1134| 1300003 | This window manager service works abnormally. | 1135| 1300004 | Unauthorized operation. | 1136 1137**示例:** 1138 1139```ts 1140import { BusinessError } from '@kit.BasicServicesKit'; 1141 1142windowClass.hideWithAnimation((err: BusinessError) => { 1143 const errCode: number = err.code; 1144 if (errCode) { 1145 console.error(`Failed to hide the window with animation. Cause code: ${err.code}, message: ${err.message}`); 1146 return; 1147 } 1148 console.info('Succeeded in hiding the window with animation.'); 1149}); 1150``` 1151 1152### hideWithAnimation<sup>9+</sup> 1153 1154hideWithAnimation(): Promise<void> 1155 1156隐藏当前窗口,过程中播放动画,使用Promise异步回调,仅支持系统窗口。 1157 1158**系统接口:** 此接口为系统接口。 1159 1160**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1161 1162**返回值:** 1163 1164| 类型 | 说明 | 1165| ------------------- | ------------------------- | 1166| Promise<void> | 无返回结果的Promise对象。 | 1167 1168**错误码:** 1169 1170以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1171 1172| 错误码ID | 错误信息 | 1173| ------- | -------------------------------------------- | 1174| 202 | Permission verification failed. A non-system application calls a system API. | 1175| 1300002 | This window state is abnormal. | 1176| 1300003 | This window manager service works abnormally. | 1177| 1300004 | Unauthorized operation. | 1178 1179**示例:** 1180 1181```ts 1182import { BusinessError } from '@kit.BasicServicesKit'; 1183 1184let promise = windowClass.hideWithAnimation(); 1185promise.then(() => { 1186 console.info('Succeeded in hiding the window with animation.'); 1187}).catch((err: BusinessError) => { 1188 console.error(`Failed to hide the window with animation. Cause code: ${err.code}, message: ${err.message}`); 1189}); 1190``` 1191 1192### showWithAnimation<sup>9+</sup> 1193 1194showWithAnimation(callback: AsyncCallback<void>): void 1195 1196显示当前窗口,过程中播放动画,使用callback异步回调,仅支持系统窗口。 1197 1198**系统接口:** 此接口为系统接口。 1199 1200**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1201 1202**参数:** 1203 1204| 参数名 | 类型 | 必填 | 说明 | 1205| -------- | ------------------------- | ---- | ---------- | 1206| callback | AsyncCallback<void> | 是 | 回调函数。 | 1207 1208**错误码:** 1209 1210以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1211 1212| 错误码ID | 错误信息 | 1213| ------- | -------------------------------------------- | 1214| 202 | Permission verification failed. A non-system application calls a system API. | 1215| 1300002 | This window state is abnormal. | 1216| 1300003 | This window manager service works abnormally. | 1217| 1300004 | Unauthorized operation. | 1218 1219**示例:** 1220 1221```ts 1222import { BusinessError } from '@kit.BasicServicesKit'; 1223 1224windowClass.showWithAnimation((err: BusinessError) => { 1225 const errCode: number = err.code; 1226 if (errCode) { 1227 console.error(`Failed to show the window with animation. Cause code: ${err.code}, message: ${err.message}`); 1228 return; 1229 } 1230 console.info('Succeeded in showing the window with animation.'); 1231}); 1232``` 1233 1234### showWithAnimation<sup>9+</sup> 1235 1236showWithAnimation(): Promise<void> 1237 1238显示当前窗口,过程中播放动画,使用Promise异步回调,仅支持系统窗口。 1239 1240**系统接口:** 此接口为系统接口。 1241 1242**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1243 1244**返回值:** 1245 1246| 类型 | 说明 | 1247| ------------------- | ------------------------- | 1248| Promise<void> | 无返回结果的Promise对象。 | 1249 1250**错误码:** 1251 1252以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 1253 1254| 错误码ID | 错误信息 | 1255| ------- | -------------------------------------------- | 1256| 202 | Permission verification failed. A non-system application calls a system API. | 1257| 1300002 | This window state is abnormal. | 1258| 1300003 | This window manager service works abnormally. | 1259| 1300004 | Unauthorized operation. | 1260 1261**示例:** 1262 1263```ts 1264import { BusinessError } from '@kit.BasicServicesKit'; 1265 1266let promise = windowClass.showWithAnimation(); 1267promise.then(() => { 1268 console.info('Succeeded in showing the window with animation.'); 1269}).catch((err: BusinessError) => { 1270 console.error(`Failed to show the window with animation. Cause code: ${err.code}, message: ${err.message}`); 1271}); 1272``` 1273 1274### setWindowMode<sup>9+</sup> 1275 1276setWindowMode(mode: WindowMode, callback: AsyncCallback<void>): void 1277 1278设置主窗口模式,使用callback异步回调。 1279 1280**系统接口:** 此接口为系统接口。 1281 1282**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1283 1284**参数:** 1285 1286| 参数名 | 类型 | 必填 | 说明 | 1287| -------- | -------------------------- | -- | --------- | 1288| mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | 1289| callback | AsyncCallback<void> | 是 | 回调函数。 | 1290 1291**错误码:** 1292 1293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1294 1295| 错误码ID | 错误信息 | 1296| ------- | -------------------------------------------- | 1297| 202 | Permission verification failed. A non-system application calls a system API. | 1298| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1299| 1300002 | This window state is abnormal. | 1300| 1300003 | This window manager service works abnormally. | 1301 1302**示例:** 1303 1304```ts 1305// EntryAbility.ets 1306import { UIAbility } from '@kit.AbilityKit'; 1307import { BusinessError } from '@kit.BasicServicesKit'; 1308 1309export default class EntryAbility extends UIAbility { 1310 // ... 1311 onWindowStageCreate(windowStage: window.WindowStage): void { 1312 console.info('onWindowStageCreate'); 1313 let windowClass: window.Window | undefined = undefined; 1314 windowStage.getMainWindow((err: BusinessError, data) => { 1315 const errCode: number = err.code; 1316 if (errCode) { 1317 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1318 return; 1319 } 1320 windowClass = data; 1321 let mode = window.WindowMode.FULLSCREEN; 1322 try { 1323 windowClass.setWindowMode(mode, (err: BusinessError) => { 1324 const errCode: number = err.code; 1325 if (errCode) { 1326 console.error(`Failed to set the window mode. Cause code: ${err.code}, message: ${err.message}`); 1327 return; 1328 } 1329 console.info('Succeeded in setting the window mode.'); 1330 }); 1331 } catch (exception) { 1332 console.error(`Failed to set the window mode. Cause code: ${exception.code}, message: ${exception.message}`); 1333 } 1334 }); 1335 } 1336} 1337``` 1338 1339### setWindowMode<sup>9+</sup> 1340 1341setWindowMode(mode: WindowMode): Promise<void> 1342 1343设置主窗口模式,使用Promise异步回调。 1344 1345**系统接口:** 此接口为系统接口。 1346 1347**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1348 1349**参数:** 1350 1351| 参数名 | 类型 | 必填 | 说明 | 1352| -------- | -------------------------- | -- | --------- | 1353| mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | 1354 1355**返回值:** 1356 1357| 类型 | 说明 | 1358| ------------------- | ----------------------- | 1359| Promise<void> | 无返回结果的Promise对象。 | 1360 1361**错误码:** 1362 1363以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1364 1365| 错误码ID | 错误信息 | 1366| ------- | -------------------------------------------- | 1367| 202 | Permission verification failed. A non-system application calls a system API. | 1368| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1369| 1300002 | This window state is abnormal. | 1370| 1300003 | This window manager service works abnormally. | 1371 1372**示例:** 1373 1374```ts 1375// EntryAbility.ets 1376import { UIAbility } from '@kit.AbilityKit'; 1377import { BusinessError } from '@kit.BasicServicesKit'; 1378 1379export default class EntryAbility extends UIAbility { 1380 // ... 1381 onWindowStageCreate(windowStage: window.WindowStage): void { 1382 console.info('onWindowStageCreate'); 1383 let windowClass: window.Window | undefined = undefined; 1384 windowStage.getMainWindow((err: BusinessError, data) => { 1385 const errCode: number = err.code; 1386 if (errCode) { 1387 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1388 return; 1389 } 1390 windowClass = data; 1391 let mode = window.WindowMode.FULLSCREEN; 1392 try { 1393 let promise = windowClass.setWindowMode(mode); 1394 promise.then(() => { 1395 console.info('Succeeded in setting the window mode.'); 1396 }).catch((err: BusinessError) => { 1397 console.error(`Failed to set the window mode. Cause code: ${err.code}, message: ${err.message}`); 1398 }); 1399 } catch (exception) { 1400 console.error(`Failed to set the window mode. Cause code: ${exception.code}, message: ${exception.message}`); 1401 } 1402 }); 1403 } 1404} 1405``` 1406 1407### bindDialogTarget<sup>9+</sup> 1408 1409bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 1410 1411绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 1412 1413**系统接口:** 此接口为系统接口。 1414 1415**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1416 1417**参数:** 1418 1419| 参数名 | 类型 | 必填 | 说明 | 1420| ----------- | ------------------------- | ---- | -------------------- | 1421| token | [rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | 1422| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 1423| callback | AsyncCallback<void> | 是 | 回调函数。 | 1424 1425**错误码:** 1426 1427以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1428 1429| 错误码ID | 错误信息 | 1430| ------- | -------------------------------------------- | 1431| 202 | Permission verification failed. A non-system application calls a system API. | 1432| 401 | Parameter error. Possible cause: Incorrect parameter types. | 1433| 1300002 | This window state is abnormal. | 1434| 1300003 | This window manager service works abnormally. | 1435 1436**示例:** 1437 1438```ts 1439import { rpc } from '@kit.IPCKit'; 1440import { BusinessError } from '@kit.BasicServicesKit'; 1441 1442class MyDeathRecipient { 1443 onRemoteDied() { 1444 console.log('server died'); 1445 } 1446} 1447 1448class TestRemoteObject extends rpc.RemoteObject { 1449 constructor(descriptor: string) { 1450 super(descriptor); 1451 } 1452 1453 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 1454 return true; 1455 } 1456 1457 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 1458 return true; 1459 } 1460 1461 isObjectDead(): boolean { 1462 return false; 1463 } 1464} 1465 1466let token: TestRemoteObject = new TestRemoteObject('testObject'); 1467let windowClass: window.Window | undefined = undefined; 1468let config: window.Configuration = { name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; 1469try { 1470 window.createWindow(config, (err: BusinessError, data) => { 1471 let errCode: number = err.code; 1472 if (errCode) { 1473 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1474 return; 1475 } 1476 windowClass = data; 1477 }); 1478 windowClass.bindDialogTarget(token, () => { 1479 console.info('Dialog Window Need Destroy.'); 1480 }, (err: BusinessError) => { 1481 let errCode: number = err.code; 1482 if (errCode) { 1483 console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); 1484 return; 1485 } 1486 console.info('Succeeded in binding dialog target.'); 1487 }); 1488} catch (exception) { 1489 console.error(`Failed to bind dialog target. Cause code: ${exception.code}, message: ${exception.message}`); 1490} 1491``` 1492 1493### bindDialogTarget<sup>9+</sup> 1494 1495bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void> 1496 1497绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 1498 1499**系统接口:** 此接口为系统接口。 1500 1501**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1502 1503**参数:** 1504 1505| 参数名 | 类型 | 必填 | 说明 | 1506| ----------- | ------------------------- | ---- | -------------------- | 1507| token | [rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | 1508| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 1509 1510**返回值:** 1511 1512| 类型 | 说明 | 1513| ------------------- | ------------------------- | 1514| Promise<void> | 无返回结果的Promise对象。 | 1515 1516**错误码:** 1517 1518以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1519 1520| 错误码ID | 错误信息 | 1521| ------- | -------------------------------------------- | 1522| 202 | Permission verification failed. A non-system application calls a system API. | 1523| 401 | Parameter error. Possible cause: Incorrect parameter types. | 1524| 1300002 | This window state is abnormal. | 1525| 1300003 | This window manager service works abnormally. | 1526 1527**示例:** 1528 1529```ts 1530import { rpc } from '@kit.IPCKit'; 1531import { BusinessError } from '@kit.BasicServicesKit'; 1532 1533class MyDeathRecipient { 1534 onRemoteDied() { 1535 console.log('server died'); 1536 } 1537} 1538 1539class TestRemoteObject extends rpc.RemoteObject { 1540 constructor(descriptor: string) { 1541 super(descriptor); 1542 } 1543 1544 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 1545 return true; 1546 } 1547 1548 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 1549 return true; 1550 } 1551 1552 isObjectDead(): boolean { 1553 return false; 1554 } 1555} 1556 1557let token: TestRemoteObject = new TestRemoteObject('testObject'); 1558let windowClass: window.Window | undefined = undefined; 1559let config: window.Configuration = { 1560 name: "test", 1561 windowType: window.WindowType.TYPE_DIALOG, 1562 ctx: this.context 1563}; 1564try { 1565 window.createWindow(config, (err: BusinessError, data) => { 1566 const errCode: number = err.code; 1567 if (errCode) { 1568 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1569 return; 1570 } 1571 windowClass = data; 1572 }); 1573 let promise = windowClass.bindDialogTarget(token, () => { 1574 console.info('Dialog Window Need Destroy.'); 1575 }); 1576 promise.then(() => { 1577 console.info('Succeeded in binding dialog target.'); 1578 }).catch((err: BusinessError) => { 1579 console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); 1580 }); 1581} catch (exception) { 1582 console.error(`Failed to bind dialog target. Cause code: ${exception.code}, message: ${exception.message}`); 1583} 1584``` 1585 1586### bindDialogTarget<sup>9+</sup> 1587 1588bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 1589 1590绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 1591 1592**系统接口:** 此接口为系统接口。 1593 1594**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1595 1596**参数:** 1597 1598| 参数名 | 类型 | 必填 | 说明 | 1599| ----------- | ------------------------- | ---- | -------------------- | 1600| requestInfo | [dialogRequest.RequestInfo](../apis-ability-kit/js-apis-app-ability-dialogRequest.md#requestinfo) | 是 | 目标窗口RequestInfo值。 | 1601| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 1602| callback | AsyncCallback<void> | 是 | 回调函数。 | 1603 1604**错误码:** 1605 1606以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1607 1608| 错误码ID | 错误信息 | 1609| ------- | -------------------------------------------- | 1610| 202 | Permission verification failed. A non-system application calls a system API. | 1611| 401 | Parameter error. Possible cause: Incorrect parameter types. | 1612| 1300002 | This window state is abnormal. | 1613| 1300003 | This window manager service works abnormally. | 1614 1615**示例:** 1616 1617```ts 1618import { dialogRequest, Want, ServiceExtensionAbility } from '@kit.AbilityKit'; 1619import { BusinessError } from '@kit.BasicServicesKit'; 1620 1621export default class ServiceExtAbility extends ServiceExtensionAbility { 1622 onRequest(want: Want, startId: number) { 1623 console.info('onRequest'); 1624 let windowClass: window.Window | undefined = undefined; 1625 let config: window.Configuration = { 1626 name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context 1627 }; 1628 try { 1629 window.createWindow(config, (err: BusinessError, data) => { 1630 let errCode: number = err.code; 1631 if (errCode) { 1632 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1633 return; 1634 } 1635 windowClass = data; 1636 }); 1637 let requestInfo = dialogRequest.getRequestInfo(want) 1638 windowClass.bindDialogTarget(requestInfo, () => { 1639 console.info('Dialog Window Need Destroy.'); 1640 }, (err: BusinessError) => { 1641 let errCode: number = err.code; 1642 if (errCode) { 1643 console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); 1644 return; 1645 } 1646 console.info('Succeeded in binding dialog target.'); 1647 }); 1648 } catch (err) { 1649 console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`) 1650 } 1651 } 1652} 1653``` 1654 1655### bindDialogTarget<sup>9+</sup> 1656 1657bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>): Promise<void> 1658 1659绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 1660 1661**系统接口:** 此接口为系统接口。 1662 1663**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1664 1665**参数:** 1666 1667| 参数名 | 类型 | 必填 | 说明 | 1668| ----------- | ------------------------- | ---- | -------------------- | 1669| requestInfo | [dialogRequest.RequestInfo](../apis-ability-kit/js-apis-app-ability-dialogRequest.md#requestinfo) | 是 | 目标窗口RequestInfo值。 | 1670| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 1671 1672**返回值:** 1673 1674| 类型 | 说明 | 1675| ------------------- | ------------------------- | 1676| Promise<void> | 无返回结果的Promise对象。 | 1677 1678**错误码:** 1679 1680以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1681 1682| 错误码ID | 错误信息 | 1683| ------- | -------------------------------------------- | 1684| 202 | Permission verification failed. A non-system application calls a system API. | 1685| 401 | Parameter error. Possible cause: Incorrect parameter types. | 1686| 1300002 | This window state is abnormal. | 1687| 1300003 | This window manager service works abnormally. | 1688 1689**示例:** 1690 1691```ts 1692import { dialogRequest, Want, ServiceExtensionAbility } from '@kit.AbilityKit'; 1693import { BusinessError } from '@kit.BasicServicesKit'; 1694 1695export default class ServiceExtAbility extends ServiceExtensionAbility { 1696 onRequest(want: Want, startId: number) { 1697 console.info('onRequest'); 1698 let windowClass: window.Window | undefined = undefined; 1699 let config: window.Configuration = { 1700 name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context 1701 }; 1702 try { 1703 window.createWindow(config, (err: BusinessError, data) => { 1704 const errCode: number = err.code; 1705 if (errCode) { 1706 console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); 1707 return; 1708 } 1709 windowClass = data; 1710 }); 1711 let requestInfo = dialogRequest.getRequestInfo(want) 1712 let promise = windowClass.bindDialogTarget(requestInfo, () => { 1713 console.info('Dialog Window Need Destroy.'); 1714 }); 1715 promise.then(() => { 1716 console.info('Succeeded in binding dialog target.'); 1717 }).catch((err: BusinessError) => { 1718 console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); 1719 }); 1720 } catch (err) { 1721 console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`) 1722 } 1723 } 1724} 1725``` 1726 1727### setWakeUpScreen<sup>9+</sup> 1728 1729setWakeUpScreen(wakeUp: boolean): void 1730 1731窗口唤醒屏幕。 1732 1733**系统接口:** 此接口为系统接口。 1734 1735**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1736 1737**参数:** 1738 1739| 参数名 | 类型 | 必填 | 说明 | 1740| ---------------- | ------- | ---- | ---------------------------- | 1741| wakeUp | boolean | 是 | 是否设置唤醒屏幕。true表示唤醒;false表示不唤醒。 | 1742 1743**错误码:** 1744 1745以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1746 1747| 错误码ID | 错误信息 | 1748| ------- | -------------------------------------------- | 1749| 202 | Permission verification failed. A non-system application calls a system API. | 1750| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1751| 1300002 | This window state is abnormal. | 1752| 1300003 | This window manager service works abnormally. | 1753 1754**示例:** 1755 1756```ts 1757let wakeUp: boolean = true; 1758try { 1759 windowClass.setWakeUpScreen(wakeUp); 1760} catch (exception) { 1761 console.error(`Failed to wake up the screen. Cause code: ${exception.code}, message: ${exception.message}`); 1762} 1763``` 1764 1765### setSnapshotSkip<sup>9+</sup> 1766setSnapshotSkip(isSkip: boolean): void 1767 1768截屏录屏是否忽略当前窗口。此接口一般用于禁止截屏/录屏的场景。 1769 1770**系统接口:** 此接口为系统接口。 1771 1772**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1773 1774**参数:** 1775 1776| 参数名 | 类型 | 必填 | 说明 | 1777| ------------- | ------- | ---- | -------------------- | 1778| isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。<br>true表示忽略当前窗口,false表示不忽略当前窗口。</br> | 1779 1780**错误码:** 1781 1782以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1783 1784| 错误码ID | 错误信息 | 1785| ------- | ------------------------------ | 1786| 202 | Permission verification failed. A non-system application calls a system API. | 1787| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1788| 1300002 | This window state is abnormal. | 1789 1790```ts 1791let isSkip: boolean = true; 1792try { 1793 windowClass.setSnapshotSkip(isSkip); 1794} catch (exception) { 1795 console.error(`Failed to Skip. Cause code: ${exception.code}, message: ${exception.message}`); 1796} 1797``` 1798 1799### setForbidSplitMove<sup>9+</sup> 1800 1801setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void 1802 1803设置主窗口在分屏模式下是否被禁止移动,使用callback异步回调。 1804 1805**系统接口:** 此接口为系统接口。 1806 1807**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1808 1809**参数:** 1810 1811| 参数名 | 类型 | 必填 | 说明 | 1812| ----------- | ------------------------- | ---- | -------------------- | 1813| isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | 1814| callback | AsyncCallback<void> | 是 | 回调函数。 | 1815 1816**错误码:** 1817 1818以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1819 1820| 错误码ID | 错误信息 | 1821| ------- | -------------------------------------------- | 1822| 202 | Permission verification failed. A non-system application calls a system API. | 1823| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1824| 1300002 | This window state is abnormal. | 1825| 1300003 | This window manager service works abnormally. | 1826 1827**示例:** 1828 1829```ts 1830// EntryAbility.ets 1831import { UIAbility } from '@kit.AbilityKit'; 1832import { BusinessError } from '@kit.BasicServicesKit'; 1833 1834export default class EntryAbility extends UIAbility { 1835 // ... 1836 onWindowStageCreate(windowStage: window.WindowStage): void { 1837 console.info('onWindowStageCreate'); 1838 let windowClass: window.Window | undefined = undefined; 1839 windowStage.getMainWindow((err: BusinessError, data) => { 1840 const errCode: number = err.code; 1841 if (errCode) { 1842 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1843 return; 1844 } 1845 windowClass = data; 1846 let isForbidSplitMove: boolean = true; 1847 try { 1848 windowClass.setForbidSplitMove(isForbidSplitMove, (err: BusinessError) => { 1849 const errCode: number = err.code; 1850 if (errCode) { 1851 console.error(`Failed to forbid window moving in split screen mode. Cause code: ${err.code}, message: ${err.message}`); 1852 return; 1853 } 1854 console.info('Succeeded in forbidding window moving in split screen mode.'); 1855 }); 1856 } catch (exception) { 1857 console.error(`Failed to forbid window moving in split screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 1858 } 1859 }); 1860 } 1861} 1862``` 1863 1864### setForbidSplitMove<sup>9+</sup> 1865 1866setForbidSplitMove(isForbidSplitMove: boolean): Promise<void> 1867 1868设置主窗口在分屏模式下是否被禁止移动,使用Promise异步回调。 1869 1870**系统接口:** 此接口为系统接口。 1871 1872**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1873 1874**参数:** 1875 1876| 参数名 | 类型 | 必填 | 说明 | 1877| ----------- | ------- | ---- | -------------------- | 1878| isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | 1879 1880**返回值:** 1881 1882| 类型 | 说明 | 1883| ------------------- | ------------------------- | 1884| Promise<void> | 无返回结果的Promise对象。 | 1885 1886**错误码:** 1887 1888以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1889 1890| 错误码ID | 错误信息 | 1891| ------- | -------------------------------------------- | 1892| 202 | Permission verification failed. A non-system application calls a system API. | 1893| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1894| 1300002 | This window state is abnormal. | 1895| 1300003 | This window manager service works abnormally. | 1896 1897**示例:** 1898 1899```ts 1900// EntryAbility.ets 1901import { UIAbility } from '@kit.AbilityKit'; 1902import { BusinessError } from '@kit.BasicServicesKit'; 1903 1904export default class EntryAbility extends UIAbility { 1905 // ... 1906 onWindowStageCreate(windowStage: window.WindowStage): void { 1907 console.info('onWindowStageCreate'); 1908 let windowClass: window.Window | undefined = undefined; 1909 windowStage.getMainWindow((err: BusinessError, data) => { 1910 const errCode: number = err.code; 1911 if (errCode) { 1912 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 1913 return; 1914 } 1915 windowClass = data; 1916 let isForbidSplitMove: boolean = true; 1917 try { 1918 let promise = windowClass.setForbidSplitMove(isForbidSplitMove); 1919 promise.then(() => { 1920 console.info('Succeeded in forbidding window moving in split screen mode.'); 1921 }).catch((err: BusinessError) => { 1922 console.error(`Failed to forbid window moving in split screen mode. Cause code: ${err.code}, message: ${err.message}`); 1923 }); 1924 } catch (exception) { 1925 console.error(`Failed to forbid window moving in split screen mode. Cause code: ${exception.code}, message: ${exception.message}`); 1926 } 1927 }); 1928 } 1929} 1930``` 1931 1932### opacity<sup>9+</sup> 1933 1934opacity(opacity: number): void 1935 1936设置窗口不透明度。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 1937 1938**系统接口:** 此接口为系统接口。 1939 1940**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1941 1942**参数:** 1943 1944| 参数名 | 类型 | 必填 | 说明 | 1945| ------- | ------ | ---- |----------------------------------------------------| 1946| opacity | number | 是 | 不透明度。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示完全透明,1.0表示完全不透明。 | 1947 1948**错误码:** 1949 1950以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1951 1952| 错误码ID | 错误信息 | 1953| ------- | ------------------------------ | 1954| 202 | Permission verification failed. A non-system application calls a system API. | 1955| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1956| 1300002 | This window state is abnormal. | 1957| 1300004 | Unauthorized operation. | 1958 1959**示例:** 1960 1961```ts 1962try { 1963 windowClass.opacity(0.5); 1964} catch (exception) { 1965 console.error(`Failed to opacity. Cause code: ${exception.code}, message: ${exception.message}`); 1966} 1967``` 1968 1969### scale<sup>9+</sup> 1970 1971scale(scaleOptions: ScaleOptions): void 1972 1973设置窗口缩放参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 1974 1975**系统接口:** 此接口为系统接口。 1976 1977**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1978 1979**参数:** 1980 1981| 参数名 | 类型 | 必填 | 说明 | 1982| ------------ | ------------------------------ | ---- | ---------- | 1983| scaleOptions | [ScaleOptions](#scaleoptions9) | 是 | 缩放参数。 | 1984 1985**错误码:** 1986 1987以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 1988 1989| 错误码ID | 错误信息 | 1990| ------- | ------------------------------ | 1991| 202 | Permission verification failed. A non-system application calls a system API. | 1992| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1993| 1300002 | This window state is abnormal. | 1994| 1300004 | Unauthorized operation. | 1995 1996**示例:** 1997 1998```ts 1999let obj: window.ScaleOptions = { 2000 x: 2.0, 2001 y: 1.0, 2002 pivotX: 0.5, 2003 pivotY: 0.5 2004}; 2005try { 2006 windowClass.scale(obj); 2007} catch (exception) { 2008 console.error(`Failed to scale. Cause code: ${exception.code}, message: ${exception.message}`); 2009} 2010``` 2011 2012### rotate<sup>9+</sup> 2013 2014rotate(rotateOptions: RotateOptions): void 2015 2016设置窗口旋转参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 2017 2018**系统接口:** 此接口为系统接口。 2019 2020**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2021 2022**参数:** 2023 2024| 参数名 | 类型 | 必填 | 说明 | 2025| ------------- | -------------------------------- | ---- | ---------- | 2026| rotateOptions | [RotateOptions](#rotateoptions9) | 是 | 旋转参数。 | 2027 2028**错误码:** 2029 2030以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2031 2032| 错误码ID | 错误信息 | 2033| ------- | ------------------------------ | 2034| 202 | Permission verification failed. A non-system application calls a system API. | 2035| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2036| 1300002 | This window state is abnormal. | 2037| 1300004 | Unauthorized operation. | 2038 2039**示例:** 2040 2041```ts 2042let obj: window.RotateOptions = { 2043 x: 1.0, 2044 y: 1.0, 2045 z: 45.0, 2046 pivotX: 0.5, 2047 pivotY: 0.5 2048}; 2049try { 2050 windowClass.rotate(obj); 2051} catch (exception) { 2052 console.error(`Failed to rotate. Cause code: ${exception.code}, message: ${exception.message}`); 2053} 2054``` 2055 2056### translate<sup>9+</sup> 2057 2058translate(translateOptions: TranslateOptions): void 2059 2060设置窗口平移参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 2061 2062**系统接口:** 此接口为系统接口。 2063 2064**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2065 2066**参数:** 2067 2068| 参数名 | 类型 | 必填 | 说明 | 2069| ---------------- | -------------------------------------- | ---- | -------------------- | 2070| translateOptions | [TranslateOptions](#translateoptions9) | 是 | 平移参数,单位为px。 | 2071 2072**错误码:** 2073 2074以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2075 2076| 错误码ID | 错误信息 | 2077| ------- | ------------------------------ | 2078| 202 | Permission verification failed. A non-system application calls a system API. | 2079| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2080| 1300002 | This window state is abnormal. | 2081| 1300004 | Unauthorized operation. | 2082 2083**示例:** 2084 2085```ts 2086let obj: window.TranslateOptions = { 2087 x: 100.0, 2088 y: 0.0, 2089 z: 0.0 2090}; 2091try { 2092 windowClass.translate(obj); 2093} catch (exception) { 2094 console.error(`Failed to translate. Cause code: ${exception.code}, message: ${exception.message}`); 2095} 2096``` 2097 2098### getTransitionController<sup>9+</sup> 2099 2100 getTransitionController(): TransitionController 2101 2102获取窗口属性转换控制器。 2103 2104**系统接口:** 此接口为系统接口。 2105 2106**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2107 2108**返回值:** 2109 2110| 类型 | 说明 | 2111| ---------------------------------------------- | ---------------- | 2112| [TransitionController](#transitioncontroller9) | 属性转换控制器。 | 2113 2114**错误码:** 2115 2116以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 2117 2118| 错误码ID | 错误信息 | 2119| ------- | ------------------------------ | 2120| 202 | Permission verification failed. A non-system application calls a system API. | 2121| 1300002 | This window state is abnormal. | 2122| 1300004 | Unauthorized operation. | 2123 2124**示例:** 2125 2126```ts 2127let controller = windowClass.getTransitionController(); // 获取属性转换控制器 2128``` 2129 2130### setBlur<sup>9+</sup> 2131 2132setBlur(radius: number): void 2133 2134设置窗口模糊。 2135 2136**系统接口:** 此接口为系统接口。 2137 2138**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2139 2140**参数:** 2141 2142| 参数名 | 类型 | 必填 | 说明 | 2143| ------ | ------ | ---- |--------------------------------------------------| 2144| radius | number | 是 | 表示窗口模糊的半径值。该参数为浮点数,单位为px,取值范围为[0, +∞),取值为0.0时表示关闭窗口模糊。 | 2145 2146**错误码:** 2147 2148以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2149 2150| 错误码ID | 错误信息 | 2151| ------- | ------------------------------ | 2152| 202 | Permission verification failed. A non-system application calls a system API. | 2153| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2154| 1300002 | This window state is abnormal. | 2155| 1300004 | Unauthorized operation. | 2156 2157**示例:** 2158 2159```ts 2160try { 2161 windowClass.setBlur(4.0); 2162} catch (exception) { 2163 console.error(`Failed to set blur. Cause code: ${exception.code}, message: ${exception.message}`); 2164} 2165``` 2166 2167### setBackdropBlur<sup>9+</sup> 2168 2169setBackdropBlur(radius: number): void 2170 2171设置窗口背景模糊。 2172窗口背景是指窗口覆盖的下层区域,与窗口大小相同。 2173需要通过[setWindowBackgroundColor](js-apis-window.md#setwindowbackgroundcolor9)将窗口内容背景设置成透明,否则无法看到模糊效果。 2174 2175**系统接口:** 此接口为系统接口。 2176 2177**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2178 2179**参数:** 2180 2181| 参数名 | 类型 | 必填 | 说明 | 2182| ------ | ------ | ---- |-------------------------------------------------------| 2183| radius | number | 是 | 表示窗口背景模糊的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0表示关闭窗口背景模糊。 | 2184 2185**错误码:** 2186 2187以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2188 2189| 错误码ID | 错误信息 | 2190| ------- | ------------------------------ | 2191| 202 | Permission verification failed. A non-system application calls a system API. | 2192| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2193| 1300002 | This window state is abnormal. | 2194| 1300004 | Unauthorized operation. | 2195 2196**示例:** 2197 2198```ts 2199try { 2200 windowClass.setWindowBackgroundColor('#00FFFFFF'); 2201 windowClass.setBackdropBlur(4.0); 2202} catch (exception) { 2203 console.error(`Failed to set backdrop blur. Cause code: ${exception.code}, message: ${exception.message}`); 2204} 2205``` 2206 2207### setBackdropBlurStyle<sup>9+</sup> 2208 2209setBackdropBlurStyle(blurStyle: BlurStyle): void 2210 2211设置窗口背景模糊类型。 2212 2213**系统接口:** 此接口为系统接口。 2214 2215**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2216 2217**参数:** 2218 2219| 参数名 | 类型 | 必填 | 说明 | 2220| --------- | --------- | ---- | ---------------------- | 2221| blurStyle | [BlurStyle](#blurstyle9) | 是 | 表示窗口背景模糊类型。 | 2222 2223**错误码:** 2224 2225以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2226 2227| 错误码ID | 错误信息 | 2228| ------- | ------------------------------ | 2229| 202 | Permission verification failed. A non-system application calls a system API. | 2230| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2231| 1300002 | This window state is abnormal. | 2232| 1300004 | Unauthorized operation. | 2233 2234**示例:** 2235 2236```ts 2237try { 2238 windowClass.setBackdropBlurStyle(window.BlurStyle.THIN); 2239} catch (exception) { 2240 console.error(`Failed to set backdrop blur style. Cause code: ${exception.code}, message: ${exception.message}`); 2241} 2242``` 2243 2244### setShadow<sup>9+</sup> 2245 2246setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void 2247 2248设置窗口边缘阴影。 2249 2250**系统接口:** 此接口为系统接口。 2251 2252**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2253 2254**参数:** 2255 2256| 参数名 | 类型 | 必填 | 说明 | 2257| ------- | ------ | ---- |-------------------------------------------------------------| 2258| radius | number | 是 | 表示窗口边缘阴影的模糊半径。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示关闭窗口边缘阴影。 | 2259| color | string | 否 | 表示窗口边缘阴影的颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 2260| offsetX | number | 否 | 表示窗口边缘阴影的X轴的偏移量。该参数为浮点数,单位为px。 | 2261| offsetY | number | 否 | 表示窗口边缘阴影的Y轴的偏移量。该参数为浮点数,单位为px。 | 2262 2263**错误码:** 2264 2265以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2266 2267| 错误码ID | 错误信息 | 2268| ------- | ------------------------------ | 2269| 202 | Permission verification failed. A non-system application calls a system API. | 2270| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2271| 1300002 | This window state is abnormal. | 2272| 1300004 | Unauthorized operation. | 2273 2274**示例:** 2275 2276```ts 2277try { 2278 windowClass.setShadow(4.0, '#FF00FF00', 2, 3); 2279} catch (exception) { 2280 console.error(`Failed to set shadow. Cause code: ${exception.code}, message: ${exception.message}`); 2281} 2282``` 2283 2284### setCornerRadius<sup>9+</sup> 2285 2286setCornerRadius(cornerRadius: number): void 2287 2288设置窗口圆角半径。 2289 2290**系统接口:** 此接口为系统接口。 2291 2292**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2293 2294**参数:** 2295 2296| 参数名 | 类型 | 必填 | 说明 | 2297| ----------- | ------- | ---- |----------------------------------------------------| 2298| cornerRadius | number | 是 | 表示窗口圆角的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。 | 2299 2300**错误码:** 2301 2302以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2303 2304| 错误码ID | 错误信息 | 2305| ------- | ------------------------------ | 2306| 202 | Permission verification failed. A non-system application calls a system API. | 2307| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2308| 1300002 | This window state is abnormal. | 2309| 1300004 | Unauthorized operation. | 2310 2311**示例:** 2312 2313```ts 2314try { 2315 windowClass.setCornerRadius(4.0); 2316} catch (exception) { 2317 console.error(`Failed to set corner radius. Cause code: ${exception.code}, message: ${exception.message}`); 2318} 2319``` 2320 2321### setTouchableAreas<sup>12+</sup> 2322 2323setTouchableAreas(rects: Array<Rect>): void 2324 2325实现设置窗口可触摸区域;不设置时默认整个窗口区域可触摸;设置窗口可触摸区域后,区域外触摸事件将被透传;如果窗口区域发生变化需要重新设置。 2326 2327**系统接口:** 此接口为系统接口。 2328 2329**系统能力:** SystemCapability.Window.SessionManager 2330 2331**参数:** 2332 2333| 参数名 | 类型 | 必填 | 说明 | 2334| -------- | ------------------------- | ---- | ---------- | 2335| rects | Array<[Rect](js-apis-window.md#rect7)> | 是 | 窗口可触摸区域。可触摸区域最大个数不能超过10个,且范围不能超出窗口区域。 | 2336 2337**错误码:** 2338 2339以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2340 2341| 错误码ID | 错误信息 | 2342| ------- | ------------------------------ | 2343| 202 | Permission verification failed. A non-system application calls a system API. | 2344| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2345| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2346| 1300002 | This window state is abnormal. | 2347| 1300003 | This window manager service works abnormally. | | 2348 2349**示例:** 2350 2351```ts 2352try { 2353 windowClass.setTouchableAreas([{left: 100, top: 100, width: 200, height:200}, 2354 {left: 400, top: 100, width: 200, height:200}]); 2355} catch (exception) { 2356 console.error(`Failed to set touchable areas. Cause code: ${exception.code}, message: ${exception.message}`); 2357} 2358``` 2359 2360### raiseToAppTop<sup>10+</sup> 2361 2362raiseToAppTop(callback: AsyncCallback<void>): void 2363 2364提升应用子窗口到应用顶层。使用callback异步回调。 2365 2366**系统接口:** 此接口为系统接口。 2367 2368**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2369 2370**参数:** 2371 2372| 参数名 | 类型 | 必填 | 说明 | 2373| -------- | ------------------------- | ---- | ---------- | 2374| callback | AsyncCallback<void> | 是 | 回调函数。 | 2375 2376**错误码:** 2377 2378以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2379 2380| 错误码ID | 错误信息 | 2381| ------- | ------------------------------ | 2382| 202 | Permission verification failed. A non-system application calls a system API. | 2383| 1300002 | This window state is abnormal. | 2384| 1300003 | This window manager service works abnormally. | 2385| 1300004 | Unauthorized operation. | 2386| 1300009 | The parent window is invalid. | 2387 2388**示例:** 2389 2390```ts 2391import { BusinessError } from '@kit.BasicServicesKit'; 2392 2393windowClass.raiseToAppTop((err: BusinessError) => { 2394 const errCode: number = err.code; 2395 if (errCode) { 2396 console.error(`Failed to raise the window to app top. Cause code: ${err.code}, message: ${err.message}`); 2397 return; 2398 } 2399 console.info('Succeeded in raising the window to app top.'); 2400}); 2401``` 2402 2403### setWaterMarkFlag<sup>10+</sup> 2404 2405setWaterMarkFlag(enable: boolean): Promise<void> 2406 2407为当前窗口添加或删除安全水印标志,使用Promise异步回调。 2408 2409**系统接口:** 此接口为系统接口。 2410 2411**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2412 2413**参数:** 2414 2415| 参数名 | 类型 | 必填 | 说明 | 2416| ------ | ------- | --- | ------------------------------------------------ | 2417| enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 | 2418 2419**返回值:** 2420 2421| 类型 | 说明 | 2422| ------------------- | ------------------------- | 2423| Promise<void> | 无返回结果的Promise对象。 | 2424 2425**错误码:** 2426 2427以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2428 2429| 错误码ID | 错误信息 | 2430| ------- | ---------------------------------------------- | 2431| 202 | Permission verification failed. A non-system application calls a system API. | 2432| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2433| 1300002 | This window state is abnormal. | 2434| 1300003 | This window manager service works abnormally. | 2435| 1300008 | The display device is abnormal. | 2436 2437**示例:** 2438 2439```ts 2440import { BusinessError } from '@kit.BasicServicesKit'; 2441 2442try { 2443 let enable = true; 2444 let promise = windowClass.setWaterMarkFlag(enable); 2445 promise.then(() => { 2446 console.info('Succeeded in setting water mark flag of window.'); 2447 }).catch((err: BusinessError) => { 2448 console.error(`Failed to set water mark flag of window. Cause code: ${err.code}, message: ${err.message}`); 2449 }); 2450} catch (exception) { 2451 console.error(`Failed to set water mark flag of window. Cause code: ${exception.code}, message: ${exception.message}`); 2452} 2453``` 2454 2455### setWaterMarkFlag<sup>10+</sup> 2456 2457setWaterMarkFlag(enable: boolean, callback: AsyncCallback<void>): void 2458 2459为当前窗口添加或删除安全水印标志,使用callback异步回调。 2460 2461**系统接口:** 此接口为系统接口。 2462 2463**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2464 2465**参数:** 2466 2467| 参数名 | 类型 | 必填 | 说明 | 2468| -------- | ------------------------- | --- | ----------------------------------------------- | 2469| enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 | 2470| callback | AsyncCallback<void> | 是 | 回调函数。 | 2471 2472**错误码:** 2473 2474以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2475 2476| 错误码ID | 错误信息 | 2477| ------- | ---------------------------------------------- | 2478| 202 | Permission verification failed. A non-system application calls a system API. | 2479| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2480| 1300002 | This window state is abnormal. | 2481| 1300003 | This window manager service works abnormally. | 2482| 1300008 | The display device is abnormal. | 2483 2484**示例:** 2485 2486```ts 2487import { BusinessError } from '@kit.BasicServicesKit'; 2488 2489try { 2490 let enable: boolean = true; 2491 windowClass.setWaterMarkFlag(enable, (err: BusinessError) => { 2492 const errCode: number = err.code; 2493 if (errCode) { 2494 console.error(`Failed to set water mark flag of window. Cause code: ${err.code}, message: ${err.message}`); 2495 return; 2496 } 2497 console.info('Succeeded in setting water mark flag of window.'); 2498 }); 2499} catch (exception) { 2500 console.error(`Failed to set water mark flag of window. Cause code: ${exception.code}, message: ${exception.message}`); 2501} 2502``` 2503 2504### setHandwritingFlag<sup>12+</sup> 2505 2506setHandwritingFlag(enable: boolean): Promise<void> 2507 2508为当前窗口添加或移除手写标志,添加该标志后窗口只响应手写笔事件,不响应触屏事件。使用Promise异步回调。 2509 2510**系统接口:** 此接口为系统接口。 2511 2512**系统能力:** SystemCapability.Window.SessionManager 2513 2514**参数:** 2515 2516| 参数名 | 类型 | 必填 | 说明 | 2517| ------ | ------- | --- | ------------------------------------------------ | 2518| enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示移除。 | 2519 2520**返回值:** 2521 2522| 类型 | 说明 | 2523| ------------------- | ------------------------- | 2524| Promise<void> | 无返回结果的Promise对象。 | 2525 2526**错误码:** 2527 2528以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2529 2530| 错误码ID | 错误信息 | 2531| ------- | -------------------------------------------- | 2532| 202 | Permission verification failed. A non-system application calls a system API. | 2533| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2534| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2535| 1300002 | This window state is abnormal. | 2536| 1300003 | This window manager service works abnormally. | 2537 2538**示例:** 2539 2540```ts 2541import { BusinessError } from '@kit.BasicServicesKit'; 2542 2543try { 2544 let enable = true; 2545 let promise = windowClass.setHandwritingFlag(enable); 2546 promise.then(() => { 2547 console.info('Succeeded in setting handwriting flag of window.'); 2548 }).catch((err: BusinessError) => { 2549 console.error(`Failed to set handwriting flag of window. Cause code: ${err.code}, message: ${err.message}`); 2550 }); 2551} catch (exception) { 2552 console.error(`Failed to set handwriting flag of window. Cause code: ${exception.code}, message: ${exception.message}`); 2553} 2554``` 2555 2556### raiseAboveTarget<sup>10+</sup> 2557 2558raiseAboveTarget(windowId: number, callback: AsyncCallback<void>): void 2559 2560将同一个主窗口下的子窗口提升到目标子窗口之上。使用callback异步回调。 2561 2562**系统接口:** 此接口为系统接口。 2563 2564**系统能力:** SystemCapability.Window.SessionManager 2565 2566**参数:** 2567 2568| 参数名 | 类型 | 必填 | 说明 | 2569| -------- | ------------------------- | ---- | ---------- | 2570| windowId | number | 是 | 目标子窗口的id,通过[getWindowProperties](js-apis-window.md#getwindowproperties9)接口获取到[properties](js-apis-window.md#windowproperties)后,再通过properties.id获取 | 2571| callback | AsyncCallback<void> | 是 | 回调函数。 | 2572 2573**错误码:** 2574 2575以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2576 2577| 错误码ID | 错误信息 | 2578| ------- | ---------------------------------------------- | 2579| 202 | Permission verification failed. A non-system application calls a system API. | 2580| 401 | Parameter error. Possible cause: Mandatory parameters are left unspecified. | 2581| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2582| 1300002 | This window state is abnormal. | 2583| 1300003 | This window manager service works abnormally. | 2584| 1300004 | Unauthorized operation. | 2585| 1300009 | The parent window is invalid. | 2586 2587**示例:** 2588 2589```ts 2590// EntryAbility.ets 2591import { UIAbility } from '@kit.AbilityKit'; 2592import { BusinessError } from '@kit.BasicServicesKit'; 2593 2594export default class EntryAbility extends UIAbility { 2595 // ... 2596 onWindowStageCreate(windowStage: window.WindowStage): void { 2597 console.info('onWindowStageCreate'); 2598 let windowClass: window.Window | undefined = undefined; 2599 // 创建子窗 2600 try { 2601 let subWindow = windowStage.createSubWindow("testSubWindow"); 2602 subWindow.then((data) => { 2603 if (data == null) { 2604 console.error("Failed to create the subWindow. Cause: The data is empty"); 2605 return; 2606 } 2607 windowClass = data; 2608 // windowClass的获取需放在targetWindow之上 2609 let targetWindow: window.Window = windowClass; 2610 let properties = targetWindow.getWindowProperties(); 2611 let targetId = properties.id; 2612 windowClass.raiseAboveTarget(targetId, (err) => { 2613 if (err.code) { 2614 console.error(`Failed to raise the subWindow to target subWindow top. Cause code: ${err.code}, message: ${err.message}`); 2615 return; 2616 } 2617 console.info('Succeeded in raising the subWindow to target subWindow top.'); 2618 }); 2619 }); 2620 } catch (exception) { 2621 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 2622 } 2623 } 2624} 2625``` 2626 2627### raiseAboveTarget<sup>10+</sup> 2628 2629raiseAboveTarget(windowId: number): Promise<void> 2630 2631将同一个主窗下的子窗口提升到目标子窗口之上。使用Promise异步回调。 2632 2633**系统接口:** 此接口为系统接口。 2634 2635**系统能力:** SystemCapability.Window.SessionManager 2636 2637**参数:** 2638 2639| 参数名 | 类型 | 必填 | 说明 | 2640| -------- | ------------------------- | ---- | ---------- | 2641| windowId | number | 是 | 目标子窗口的id,通过[getWindowProperties](js-apis-window.md#getwindowproperties9)接口获取到[properties](js-apis-window.md#windowproperties)后,再通过properties.id获取 | 2642 2643**返回值:** 2644 2645| 类型 | 说明 | 2646| ------------------- | ------------------------- | 2647| Promise<void> | 无返回结果的Promise对象。 | 2648 2649**错误码:** 2650 2651以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2652 2653| 错误码ID | 错误信息 | 2654| ------- | ------------------------------ | 2655| 202 | Permission verification failed. A non-system application calls a system API. | 2656| 401 | Parameter error. Possible cause: Mandatory parameters are left unspecified. | 2657| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2658| 1300002 | This window state is abnormal. | 2659| 1300003 | This window manager service works abnormally. | 2660| 1300004 | Unauthorized operation. | 2661| 1300009 | The parent window is invalid. | 2662 2663**示例:** 2664 2665```ts 2666// EntryAbility.ets 2667import { UIAbility } from '@kit.AbilityKit'; 2668import { BusinessError } from '@kit.BasicServicesKit'; 2669 2670export default class EntryAbility extends UIAbility { 2671 // ... 2672 onWindowStageCreate(windowStage: window.WindowStage): void { 2673 console.info('onWindowStageCreate'); 2674 let windowClass: window.Window | undefined = undefined; 2675 // 创建子窗 2676 try { 2677 let subWindow = windowStage.createSubWindow("testSubWindow"); 2678 subWindow.then((data) => { 2679 if (data == null) { 2680 console.error("Failed to create the subWindow. Cause: The data is empty"); 2681 return; 2682 } 2683 windowClass = data; 2684 // windowClass的获取需放在targetWindow之上 2685 let targetWindow: window.Window = windowClass; 2686 let properties = targetWindow.getWindowProperties(); 2687 let targetId = properties.id; 2688 let promise = windowClass.raiseAboveTarget(targetId); 2689 promise.then(()=> { 2690 console.info('Succeeded in raising the subWindow to target subWindow top.'); 2691 }).catch((err: BusinessError)=>{ 2692 console.error(`Failed to raise the subWindow to target subWindow top. Cause code: ${err.code}, message: ${err.message}`); 2693 }); 2694 }); 2695 } catch (exception) { 2696 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 2697 } 2698 } 2699} 2700``` 2701 2702### setRaiseByClickEnabled<sup>10+</sup> 2703 2704setRaiseByClickEnabled(enable: boolean, callback: AsyncCallback<void>): void 2705 2706禁止/使能子窗口点击抬升功能。使用callback异步回调。 2707 2708通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。 2709 2710**系统接口:** 此接口为系统接口。 2711 2712**系统能力:** SystemCapability.Window.SessionManager 2713 2714**参数:** 2715 2716| 参数名 | 类型 | 必填 | 说明 | 2717| -------- | ------------------------- | ---- | ---------- | 2718| enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | 2719| callback | AsyncCallback<void> | 是 | 回调函数。 | 2720 2721**错误码:** 2722 2723以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2724 2725| 错误码ID | 错误信息 | 2726| ------- | ------------------------------ | 2727| 202 | Permission verification failed. A non-system application calls a system API. | 2728| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2729| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2730| 1300002 | This window state is abnormal. | 2731| 1300003 | This window manager service works abnormally. | 2732| 1300004 | Unauthorized operation. | 2733| 1300009 | The parent window is invalid. | 2734 2735**示例:** 2736 2737```ts 2738// EntryAbility.ets 2739import { UIAbility } from '@kit.AbilityKit'; 2740import { BusinessError } from '@kit.BasicServicesKit'; 2741 2742export default class EntryAbility extends UIAbility { 2743 // ... 2744 onWindowStageCreate(windowStage: window.WindowStage): void { 2745 console.info('onWindowStageCreate'); 2746 let windowClass: window.Window | undefined = undefined; 2747 // 创建子窗 2748 try { 2749 let subWindow = windowStage.createSubWindow("testSubWindow"); 2750 subWindow.then((data) => { 2751 if (data == null) { 2752 console.error("Failed to create the subWindow. Cause: The data is empty"); 2753 return; 2754 } 2755 windowClass = data; 2756 let enabled = false; 2757 windowClass.setRaiseByClickEnabled(enabled, (err) => { 2758 if (err.code) { 2759 console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); 2760 return; 2761 } 2762 console.info('Succeeded in disabling the raise-by-click function.'); 2763 }); 2764 }); 2765 } catch (exception) { 2766 console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); 2767 } 2768 } 2769} 2770``` 2771 2772### enableDrag<sup>14+</sup> 2773 2774enableDrag(enable: boolean): Promise<void> 2775 2776使能/禁止拖拽窗口。使用Promise异步回调。 2777 2778使能后,将允许通过鼠标对窗口进行拉伸操作。 2779 2780仅对2in1设备的系统窗口生效,其它设备类型调用此接口会报错。 2781 2782**系统能力:** SystemCapability.Window.SessionManager 2783 2784**系统接口:** 此接口为系统接口。 2785 2786**参数:** 2787 2788| 参数名 | 类型 | 必填 | 说明 | 2789| -------- | ---------------------------- | -- | --------- | 2790| enable| boolean | 是 | 是否允许拖拽。<br>true表示允许,false表示不允许。</br> | 2791 2792**返回值:** 2793 2794| 类型 | 说明 | 2795| ------------------- | ------------------------- | 2796| Promise<void> | 无返回结果的Promise对象。 | 2797 2798**错误码:** 2799 2800以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2801 2802| 错误码ID | 错误信息 | 2803| -------- | -------------------------------------------- | 2804| 202 | Permission verification failed. A non-system application calls a system API. | 2805| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2806| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2807| 1300002 | This window state is abnormal. | 2808| 1300003 | This window manager service works abnormally. | 2809| 1300004 | Unauthorized operation. | 2810 2811**示例:** 2812 2813```ts 2814import { BusinessError } from '@kit.BasicServicesKit'; 2815 2816try { 2817 windowClass.enableDrag(true).then(() => { 2818 console.info('succeeded in setting window draggable'); 2819 }).catch((err: BusinessError) => { 2820 console.error(`Failed to set window draggable. Cause code: ${err.code}, message: ${err.message}`); 2821 }); 2822} catch (exception) { 2823 console.error(`Failed to set window draggable. Cause code: ${exception.code}, message: ${exception.message}`); 2824} 2825``` 2826 2827### hideNonSystemFloatingWindows<sup>11+</sup> 2828 2829hideNonSystemFloatingWindows(shouldHide: boolean, callback: AsyncCallback<void>): void 2830 2831设置是否隐藏非系统级悬浮窗口。使用callback异步回调。 2832 2833非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。 2834 2835**系统接口:** 此接口为系统接口。 2836 2837**系统能力:** SystemCapability.Window.SessionManager 2838 2839**参数:** 2840 2841| 参数名 | 类型 | 必填 | 说明 | 2842| ----------- | ------------------------- | ---- | ---------- | 2843| shouldHide | boolean | 是 | 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。 | 2844| callback | AsyncCallback<void> | 是 | 回调函数。 | 2845 2846**错误码:** 2847 2848以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2849 2850| 错误码ID | 错误信息 | 2851| ------- | ------------------------------ | 2852| 202 | Permission verification failed. A non-system application calls a system API. | 2853| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2854| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2855| 1300002 | This window state is abnormal. | 2856| 1300003 | This window manager service works abnormally. | 2857| 1300004 | Unauthorized operation. | 2858 2859**示例:** 2860 2861```ts 2862// EntryAbility.ets 2863import { UIAbility, Want } from '@kit.AbilityKit'; 2864 2865export default class EntryAbility extends UIAbility { 2866 onWindowStageCreate(windowStage: window.WindowStage) { 2867 // 加载主窗口对应的页面 2868 windowStage.loadContent('pages/Index', (err) => { 2869 if (err.code) { 2870 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2871 return; 2872 } 2873 console.info('Succeeded in loading the content.'); 2874 }); 2875 2876 // 获取应用主窗口。 2877 let mainWindow: window.Window | undefined = undefined; 2878 windowStage.getMainWindow((err, data) => { 2879 if (err.code) { 2880 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2881 return; 2882 } 2883 mainWindow = data; 2884 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2885 2886 let shouldHide = true; 2887 // 调用带callback参数的hideNonSystemFloatingWindows接口 2888 mainWindow.hideNonSystemFloatingWindows(shouldHide, (err) => { 2889 if (err.code) { 2890 console.error(`Failed to hide the non-system floating windows. Cause code: ${err.code}, message: ${err.message}`); 2891 return; 2892 } 2893 console.info('Succeeded in hiding the non-system floating windows.'); 2894 }); 2895 }); 2896 } 2897} 2898``` 2899 2900### hideNonSystemFloatingWindows<sup>11+</sup> 2901 2902hideNonSystemFloatingWindows(shouldHide: boolean): Promise<void> 2903 2904设置是否隐藏非系统级悬浮窗口。使用callback异步回调。 2905 2906非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。 2907 2908**系统接口:** 此接口为系统接口。 2909 2910**系统能力:** SystemCapability.Window.SessionManager 2911 2912**参数:** 2913 2914| 参数名 | 类型 | 必填 | 说明 | 2915| ----------- | ------------------------- | ---- | ---------- | 2916| shouldHide | boolean | 是 | 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。 | 2917 2918**返回值:** 2919 2920| 类型 | 说明 | 2921| ------------------- | ------------------------- | 2922| Promise<void> | 无返回结果的Promise对象。 | 2923 2924**错误码:** 2925 2926以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 2927 2928| 错误码ID | 错误信息 | 2929| ------- | ------------------------------ | 2930| 202 | Permission verification failed. A non-system application calls a system API. | 2931| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2932| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 2933| 1300002 | This window state is abnormal. | 2934| 1300003 | This window manager service works abnormally. | 2935| 1300004 | Unauthorized operation. | 2936 2937**示例:** 2938 2939```ts 2940// EntryAbility.ets 2941import { UIAbility, Want } from '@kit.AbilityKit'; 2942import { BusinessError } from '@kit.BasicServicesKit'; 2943 2944export default class EntryAbility extends UIAbility { 2945 onWindowStageCreate(windowStage: window.WindowStage) { 2946 // 加载主窗口对应的页面 2947 windowStage.loadContent('pages/Index', (err) => { 2948 if (err.code) { 2949 console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); 2950 return; 2951 } 2952 console.info('Succeeded in loading the content.'); 2953 }); 2954 2955 // 获取应用主窗口。 2956 let mainWindow: window.Window | undefined = undefined; 2957 windowStage.getMainWindow((err, data) => { 2958 if (err.code) { 2959 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 2960 return; 2961 } 2962 mainWindow = data; 2963 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2964 2965 let shouldHide = true; 2966 // 调用hideNonSystemFloatingWindows接口,获取promise对象 2967 let promise = mainWindow.hideNonSystemFloatingWindows(shouldHide); 2968 promise.then(()=> { 2969 console.info('Succeeded in hiding the non-system floating windows.'); 2970 }).catch((err: BusinessError)=>{ 2971 console.error(`Failed to hide the non-system floating windows. Cause code: ${err.code}, message: ${err.message}`); 2972 }); 2973 }); 2974 } 2975} 2976``` 2977 2978### setTopmost<sup>12+</sup> 2979 2980setTopmost(isTopmost: boolean): Promise<void> 2981 2982系统应用主窗口调用,实现将窗口置于所有应用窗口之上不被遮挡,使用Promise异步回调。 2983 2984仅对2in1设备的悬浮窗口生效。 2985 2986**系统接口:** 此接口为系统接口。 2987 2988**系统能力:** SystemCapability.Window.SessionManager 2989 2990**参数:** 2991 2992| 参数名 | 类型 | 必填 | 说明 | 2993| -------- | ------------------------- | ---- | ---------- | 2994| isTopmost | boolean | 是 | 是否将系统应用主窗口置顶,true表示置顶,false表示取消置顶。 | 2995 2996**返回值:** 2997 2998| 类型 | 说明 | 2999| ------------------- | ------------------------- | 3000| Promise<void> | 无返回结果的Promise对象。 | 3001 3002**错误码:** 3003 3004以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3005 3006| 错误码ID | 错误信息 | 3007| ------- | ------------------------------ | 3008| 202 | Permission verification failed. A non-system application calls a system API. | 3009| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3010| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3011| 1300002 | This window state is abnormal. | 3012| 1300003 | This window manager service works abnormally. | 3013| 1300004 | Unauthorized operation. | 3014 3015**示例:** 3016 3017```ts 3018// EntryAbility.ets 3019import { UIAbility } from '@kit.AbilityKit'; 3020import { BusinessError } from '@kit.BasicServicesKit'; 3021 3022export default class EntryAbility extends UIAbility { 3023 // ... 3024 onWindowStageCreate(windowStage: window.WindowStage): void { 3025 // ... 3026 windowStage.getMainWindow().then((window) => { 3027 let isTopmost: boolean = true; 3028 let promise = window.setTopmost(isTopmost); 3029 promise.then(() => { 3030 console.info('Succeeded in setting the main window to be topmost.'); 3031 }).catch((err: BusinessError) => { 3032 console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); 3033 }); 3034 }); 3035 } 3036} 3037``` 3038 3039### setSingleFrameComposerEnabled<sup>11+</sup> 3040 3041setSingleFrameComposerEnabled(enable: boolean): Promise<void> 3042 3043禁止/使能单帧合成渲染节点的功能。使用Promise异步回调。 3044 3045单帧合成渲染节点的功能主要用于跟手性要求较高的场景,使能该功能之后可以降低渲染节点的上屏延时。通过setSingleFrameComposerEnabled接口,如果enable设置为true,则使能单帧合成渲染节点的功能,否则禁止单帧合成渲染节点的功能。 3046 3047**系统接口:** 此接口为系统接口。 3048 3049**系统能力:** SystemCapability.Window.SessionManager 3050 3051**参数:** 3052 3053| 参数名 | 类型 | 必填 | 说明 | 3054| -------- | ------------------------- | ---- | ---------- | 3055| enable | boolean | 是 | 设置单帧合成渲染节点的功能是否使能,true表示使能,false表示禁止。 | 3056 3057**返回值:** 3058 3059| 类型 | 说明 | 3060| ------------------- | ------------------------- | 3061| Promise<void> | 无返回结果的Promise对象。 | 3062 3063**错误码:** 3064 3065以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3066 3067| 错误码ID | 错误信息 | 3068| ------- | ------------------------------ | 3069| 202 | Permission verification failed. A non-system application calls a system API. | 3070| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3071| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3072| 1300002 | This window state is abnormal. | 3073 3074**示例:** 3075 3076```ts 3077import { BusinessError } from '@kit.BasicServicesKit'; 3078 3079let enable = true; 3080let promise = windowClass.setSingleFrameComposerEnabled(enable); 3081promise.then(()=> { 3082 console.info('Succeeded in enabling the single-frame-composer function.'); 3083}).catch((err: BusinessError)=>{ 3084 console.error(`Failed to enable the single-frame-composer function. code:${err.code}, message:${err.message}.`); 3085}); 3086``` 3087 3088### setTitleButtonVisible<sup>12+</sup> 3089 3090setTitleButtonVisible(isMaximizeVisible: boolean, isMinimizeVisible: boolean, isSplitVisible: boolean): void 3091 3092设置主窗标题栏上的最大化、最小化、分屏按钮是否可见。 3093 3094此接口仅支持2in1设备且仅对在当前场景下可见的标题栏按钮(最大化、最小化、分屏)生效。 3095 3096**系统接口:** 此接口为系统接口。 3097 3098**系统能力:** SystemCapability.Window.SessionManager 3099 3100**参数:** 3101 3102| 参数名 | 类型 | 必填 | 说明 | 3103| --------- | ------- | ---- | --------------------------------------------- | 3104| isMaximizeVisible | boolean | 是 | 设置最大化按钮是否可见,true为可见,false为隐藏。 | 3105| isMinimizeVisible | boolean | 是 | 设置最小化按钮是否可见,true为可见,false为隐藏。 | 3106| isSplitVisible | boolean | 是 | 设置分屏按钮是否可见,true为可见,false为隐藏。 | 3107 3108**错误码:** 3109 3110以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3111 3112| 错误码ID | 错误信息 | 3113| -------- | ------------------------------ | 3114| 202 | Permission verification failed. A non-system application calls a system API. | 3115| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3116| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3117| 1300002 | This window state is abnormal. | 3118| 1300004 | Unauthorized operation. | 3119 3120**示例:** 3121 3122```ts 3123// EntryAbility.ets 3124import { UIAbility } from '@kit.AbilityKit'; 3125import { BusinessError } from '@kit.BasicServicesKit'; 3126 3127export default class EntryAbility extends UIAbility { 3128 onWindowStageCreate(windowStage: window.WindowStage): void { 3129 // 加载主窗口对应的页面 3130 windowStage.loadContent('pages/Index', (err) => { 3131 let mainWindow: window.Window | undefined = undefined; 3132 // 获取应用主窗口。 3133 windowStage.getMainWindow().then( 3134 data => { 3135 mainWindow = data; 3136 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 3137 // 调用setTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化、分屏按钮。 3138 mainWindow.setTitleButtonVisible(false, false, false); 3139 } 3140 ).catch((err: BusinessError) => { 3141 if(err.code){ 3142 console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); 3143 } 3144 }); 3145 }); 3146 } 3147} 3148``` 3149 3150### setWindowType<sup>(deprecated)</sup> 3151 3152setWindowType(type: WindowType, callback: AsyncCallback<void>): void 3153 3154设置窗口类型,使用callback异步回调。 3155 3156**系统接口:** 此接口为系统接口。 3157 3158> **说明:** 3159> 3160> 从 API version 7开始支持,从API version 9开始废弃。 3161 3162**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3163 3164**参数:** 3165 3166| 参数名 | 类型 | 必填 | 说明 | 3167| -------- | ------------------------- | ---- | ---------- | 3168| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 3169| callback | AsyncCallback<void> | 是 | 回调函数。 | 3170 3171**示例:** 3172 3173```ts 3174import { BusinessError } from '@kit.BasicServicesKit'; 3175 3176let type = window.WindowType.TYPE_SYSTEM_ALERT; 3177windowClass.setWindowType(type, (err: BusinessError) => { 3178 const errCode: number = err.code; 3179 if (errCode) { 3180 console.error(`Failed to set the window type. Cause code: ${err.code}, message: ${err.message}`); 3181 return; 3182 } 3183 console.info('Succeeded in setting the window type.'); 3184}); 3185``` 3186 3187### setWindowType<sup>(deprecated)</sup> 3188 3189setWindowType(type: WindowType): Promise<void> 3190 3191设置窗口类型,使用Promise异步回调。 3192 3193**系统接口:** 此接口为系统接口。 3194 3195> **说明:** 3196> 3197> 从 API version 7开始支持,从API version 9开始废弃。 3198 3199**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3200 3201**参数:** 3202 3203| 参数名 | 类型 | 必填 | 说明 | 3204| ------ | ------------------------- | ---- | ---------- | 3205| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 3206 3207**返回值:** 3208 3209| 类型 | 说明 | 3210| ------------------- | ------------------------- | 3211| Promise<void> | 无返回结果的Promise对象。 | 3212 3213**示例:** 3214 3215```ts 3216import { BusinessError } from '@kit.BasicServicesKit'; 3217 3218let type = window.WindowType.TYPE_SYSTEM_ALERT; 3219let promise = windowClass.setWindowType(type); 3220promise.then(() => { 3221 console.info('Succeeded in setting the window type.'); 3222}).catch((err: BusinessError) => { 3223 console.error(`Failed to set the window type. Cause code: ${err.code}, message: ${err.message}`); 3224}); 3225``` 3226 3227### requestFocus<sup>13+</sup> 3228 3229requestFocus(isFocused: boolean): Promise<void> 3230 3231支持当前窗口主动请求获焦/失焦,使用Promise异步回调。调用成功即返回,该接口返回值不代表最终获焦/失焦生效结果。可使用[on('windowEvent')](js-apis-window.md#onwindowevent10)监听窗口获焦/失焦状态。 3232 3233获焦请求发送后,窗口获焦结果受到窗口可获焦属性及窗口可见状态的限制。获焦成功的窗口需满足以下约束:1.窗口支持获焦;2.窗口可见(窗口已显示,未销毁且未退至后台)。 3234 3235失焦请求发送后,窗口无条件失焦。 3236 3237**系统接口:** 此接口为系统接口。 3238 3239**系统能力:** SystemCapability.Window.SessionManager 3240 3241**参数:** 3242 3243| 参数名 | 类型 | 必填 | 说明 | 3244| -------- | ------------------------- | ---- | ---------- | 3245| isFocused | boolean | 是 | 是否获取焦点,true表示请求获焦,false表示请求失焦。 | 3246 3247**返回值:** 3248 3249| 类型 | 说明 | 3250| ------------------- | ------------------------- | 3251| Promise<void> | 无返回结果的Promise对象。 | 3252 3253**错误码:** 3254 3255以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3256 3257| 错误码ID | 错误信息 | 3258| ------- | ------------------------------ | 3259| 202 | Permission verification failed. A non-system application calls a system API. | 3260| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3261| 801 | Capability not supported. Failed to call the API due to limited device capabilities. | 3262| 1300002 | This window state is abnormal. | 3263| 1300003 | This window manager service works abnormally. | 3264 3265**示例:** 3266 3267```ts 3268import { BusinessError } from '@kit.BasicServicesKit'; 3269 3270let isFocused: boolean = true; 3271let promise = windowClass.requestFocus(isFocused); 3272promise.then(() => { 3273 console.info('Succeeded in requesting focus.'); 3274}).catch((err: BusinessError) => { 3275 console.error(`Failed to request focus. Cause code: ${err.code}, message: ${err.message}`); 3276}); 3277``` 3278 3279## SubWindowOptions<sup>11+</sup> 3280 3281子窗口创建参数。 3282 3283**系统能力:** SystemCapability.Window.SessionManager 3284 3285| 名称 | 类型 | 只读 | 可选 | 说明 | 3286| ---------- | ---- | ---- | ---- | ----------- | 3287| isTopmost<sup>12+</sup> | boolean | 否 | 是 | 子窗口是否启用置顶属性。true表示子窗口置顶,false表示子窗口不置顶。不设置,则默认为false。 | 3288 3289## WindowStage<sup>9+</sup> 3290 3291窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 3292 3293下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 3294 3295### disableWindowDecor<sup>9+</sup> 3296 3297disableWindowDecor(): void 3298 3299禁止窗口装饰。 3300 3301禁止窗口装饰后,当主窗口进入全屏沉浸状态时,此时鼠标Hover到上方窗口标题栏热区上会显示悬浮标题栏。若想禁用悬浮标题栏显示,请使用[setTitleAndDockHoverShown()](./js-apis-window.md#settitleanddockhovershown14)接口。 3302 3303**模型约束:** 此接口仅可在Stage模型下使用。 3304 3305**系统接口:** 此接口为系统接口。 3306 3307**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3308 3309**错误码:** 3310 3311以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 3312 3313| 错误码ID | 错误信息 | 3314| ------- | ------------------------------ | 3315| 202 | Permission verification failed. A non-system application calls a system API. | 3316| 1300002 | This window state is abnormal. | 3317| 1300005 | This window stage is abnormal. | 3318 3319**示例:** 3320 3321```ts 3322// EntryAbility.ets 3323import { UIAbility, Want } from '@kit.AbilityKit'; 3324 3325export default class EntryAbility extends UIAbility { 3326 // ... 3327 3328 onWindowStageCreate(windowStage: window.WindowStage) { 3329 console.log('disableWindowDecor'); 3330 windowStage.disableWindowDecor(); 3331 } 3332}; 3333``` 3334 3335### setShowOnLockScreen<sup>9+</sup> 3336 3337setShowOnLockScreen(showOnLockScreen: boolean): void 3338 3339设置应用显示在锁屏之上。 3340 3341**系统接口:** 此接口为系统接口。 3342 3343**模型约束:** 此接口仅可在Stage模型下使用。 3344 3345**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3346 3347**参数:** 3348 3349| 参数名 | 类型 | 必填 | 说明 | 3350| ---------------- | ------- | ---- | ---------------------------- | 3351| showOnLockScreen | boolean | 是 | 是否设置应用显示在锁屏之上。true表示显示在锁屏之上;false表示不显示在锁屏之上。 | 3352 3353**错误码:** 3354 3355以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 3356 3357| 错误码ID | 错误信息 | 3358| ------- | ------------------------------ | 3359| 202 | Permission verification failed. A non-system application calls a system API. | 3360| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3361| 1300002 | This window state is abnormal. | 3362| 1300005 | This window stage is abnormal. | 3363 3364**示例:** 3365 3366```ts 3367// EntryAbility.ets 3368import { UIAbility } from '@kit.AbilityKit'; 3369 3370export default class EntryAbility extends UIAbility { 3371 // ... 3372 3373 onWindowStageCreate(windowStage: window.WindowStage) { 3374 console.log('onWindowStageCreate'); 3375 try { 3376 windowStage.setShowOnLockScreen(true); 3377 } catch (exception) { 3378 console.error(`Failed to show on lockscreen. Cause code: ${exception.code}, message: ${exception.message}`); 3379 } 3380 } 3381}; 3382``` 3383 3384## TransitionContext<sup>9+</sup> 3385 3386属性转换的上下文信息。 3387 3388**系统接口:** 此接口为系统接口。 3389 3390### 属性 3391 3392**系统接口:** 此接口为系统接口。 3393 3394**系统能力**:SystemCapability.WindowManager.WindowManager.Core 3395 3396| 名称 | 类型 | 可读 | 可写 | 说明 | 3397| --------------------- | ----------------- | ---- | ---- | ---------------- | 3398| toWindow<sup>9+</sup> | [Window](#window) | 是 | 是 | 动画的目标窗口。 | 3399 3400### completeTransition<sup>9+</sup> 3401 3402completeTransition(isCompleted: boolean): void 3403 3404设置属性转换的最终完成状态。该函数需要在动画函数[animateTo()](arkui-ts/ts-explicit-animation.md)执行后设置。 3405 3406**系统接口:** 此接口为系统接口。 3407 3408**系统能力**:SystemCapability.WindowManager.WindowManager.Core 3409 3410**参数:** 3411 3412| 参数名 | 类型 | 必填 | 说明 | 3413| ----------- | ------- | ---- | ------------------------------------------------------------ | 3414| isCompleted | boolean | 是 | 窗口属性转换是否完成。true表示完成本次转换;false表示撤销本次转换。 | 3415 3416**错误码:** 3417 3418以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3419 3420| 错误码ID | 错误信息 | 3421| ------- | -------------------------------- | 3422| 202 | Permission verification failed. A non-system application calls a system API. | 3423| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3424 3425**示例:** 3426 3427```ts 3428(context: window.TransitionContext) => { 3429 let toWindow: window.Window = context.toWindow; 3430 animateTo({ 3431 duration: 1000, // 动画时长 3432 tempo: 0.5, // 播放速率 3433 curve: Curve.EaseInOut, // 动画曲线 3434 delay: 0, // 动画延迟 3435 iterations: 1, // 播放次数 3436 playMode: PlayMode.Normal, // 动画模式 3437 }, () => { 3438 let obj: window.TranslateOptions = { 3439 x: 100.0, 3440 y: 0.0, 3441 z: 0.0 3442 }; 3443 toWindow.translate(obj); 3444 console.info('toWindow translate end'); 3445 } 3446 ); 3447 try { 3448 context.completeTransition(true) 3449 } catch (exception) { 3450 console.error(`toWindow translate fail. Cause code: ${exception.code}, message: ${exception.message}`); 3451 } 3452 console.info('complete transition end'); 3453}; 3454``` 3455 3456## TransitionController<sup>9+</sup> 3457 3458属性转换控制器。使用其子接口之前得先创建系统窗口,参照示例代码。 3459 3460**系统接口:** 此接口为系统接口。 3461 3462**示例:** 3463 3464```ts 3465import { BusinessError } from '@kit.BasicServicesKit'; 3466 3467let windowClass: window.Window | undefined = undefined; 3468let config: window.Configuration = { 3469 name: "systemTypeWindow", 3470 windowType: window.WindowType.TYPE_PANEL, //根据需要自选系统窗口类型 3471 ctx: this.context 3472}; 3473let promise = window.createWindow(config); 3474promise.then((data) => { 3475 windowClass = data; 3476 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 3477}).catch((err: BusinessError) => { 3478 console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); 3479}); 3480``` 3481 3482### animationForShown<sup>9+</sup> 3483 3484animationForShown(context: TransitionContext): void 3485 3486窗口显示时的自定义动画配置。 3487 3488**系统接口:** 此接口为系统接口。 3489 3490**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3491 3492**参数:** 3493 3494| 参数名 | 类型 | 必填 | 说明 | 3495| ------- | ---------------------------------------- | ---- | -------------------- | 3496| context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | 3497 3498**错误码:** 3499 3500以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3501 3502| 错误码ID | 错误信息 | 3503| ------- | -------------------------------- | 3504| 202 | Permission verification failed. A non-system application calls a system API. | 3505| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3506 3507**示例:** 3508 3509```ts 3510// xxx.ts 3511export class AnimationConfig { 3512 private animationForShownCallFunc_: Function = undefined; 3513 ShowWindowWithCustomAnimation(windowClass: window.Window, callback) { 3514 if (!windowClass) { 3515 console.error('windowClass is undefined'); 3516 return false; 3517 } 3518 this.animationForShownCallFunc_ = callback; 3519 let controller: window.TransitionController = windowClass.getTransitionController(); 3520 controller.animationForShown = (context : window.TransitionContext)=> { 3521 this.animationForShownCallFunc_(context); 3522 }; 3523 windowClass.showWithAnimation(()=>{ 3524 console.info('Show with animation success'); 3525 }); 3526 } 3527} 3528``` 3529 3530```ts 3531// xxx.ets 3532let animationConfig = new AnimationConfig(); 3533let systemTypeWindow = window.findWindow("systemTypeWindow"); // 此处需要获取一个系统类型窗口。 3534try { 3535 animationConfig?.ShowWindowWithCustomAnimation(systemTypeWindow, (context : window.TransitionContext)=>{ 3536 console.info('complete transition end'); 3537 let toWindow = context.toWindow; 3538 animateTo({ 3539 duration: 1000, // 动画时长 3540 tempo: 0.5, // 播放速率 3541 curve: Curve.EaseInOut, // 动画曲线 3542 delay: 0, // 动画延迟 3543 iterations: 1, // 播放次数 3544 playMode: PlayMode.Normal, // 动画模式 3545 onFinish: () => { 3546 console.info('onFinish in animation'); 3547 context.completeTransition(true) 3548 } 3549 }, () => { 3550 let obj : window.TranslateOptions = { 3551 x : 100.0, 3552 y : 0.0, 3553 z : 0.0 3554 }; 3555 toWindow.translate(obj); // 设置动画过程中的属性转换 3556 console.info('toWindow translate end in animation'); 3557 }); 3558 console.info('complete transition end'); 3559 }); 3560} catch (error) { 3561 console.error(`ShowWindowWithCustomAnimation error code: ${error.code}, message: ${error.message}`); 3562} 3563``` 3564 3565### animationForHidden<sup>9+</sup> 3566 3567animationForHidden(context: TransitionContext): void 3568 3569窗口隐藏时的自定义动画配置。 3570 3571**系统接口:** 此接口为系统接口。 3572 3573**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3574 3575**参数:** 3576 3577| 参数名 | 类型 | 必填 | 说明 | 3578| ------- | ---------------------------------------- | ---- | -------------------- | 3579| context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | 3580 3581**错误码:** 3582 3583以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3584 3585| 错误码ID | 错误信息 | 3586| ------- | -------------------------------- | 3587| 202 | Permission verification failed. A non-system application calls a system API. | 3588| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3589 3590**示例:** 3591 3592```ts 3593// xxx.ts 3594export class AnimationConfig { 3595 private animationForHiddenCallFunc_: Function = undefined; 3596 HideWindowWithCustomAnimation(windowClass: window.Window, callback) { 3597 if (!windowClass) { 3598 console.error('windowClass is undefined'); 3599 return false; 3600 } 3601 this.animationForHiddenCallFunc_ = callback; 3602 let controller: window.TransitionController = windowClass.getTransitionController(); 3603 controller.animationForHidden = (context : window.TransitionContext)=> { 3604 this.animationForHiddenCallFunc_(context); 3605 }; 3606 windowClass.hideWithAnimation(()=>{ 3607 console.info('hide with animation success'); 3608 }); 3609 } 3610} 3611``` 3612 3613```ts 3614// xxx.ets 3615let animationConfig = new AnimationConfig(); 3616let systemTypeWindow = window.findWindow("systemTypeWindow"); // 此处需要获取一个系统类型窗口。 3617try { 3618 animationConfig?.HideWindowWithCustomAnimation(systemTypeWindow, (context : window.TransitionContext)=>{ 3619 console.info('complete transition end'); 3620 let toWindow = context.toWindow; 3621 animateTo({ 3622 duration: 1000, // 动画时长 3623 tempo: 0.5, // 播放速率 3624 curve: Curve.EaseInOut, // 动画曲线 3625 delay: 0, // 动画延迟 3626 iterations: 1, // 播放次数 3627 playMode: PlayMode.Normal, // 动画模式 3628 onFinish: () => { 3629 console.info('onFinish in animation'); 3630 context.completeTransition(true) 3631 } 3632 }, () => { 3633 let obj : window.TranslateOptions = { 3634 x : 100.0, 3635 y : 0.0, 3636 z : 0.0 3637 }; 3638 toWindow.translate(obj); // 设置动画过程中的属性转换 3639 console.info('toWindow translate end in animation'); 3640 }); 3641 console.info('complete transition end'); 3642 }); 3643} catch (error) { 3644 console.error(`HideWindowWithCustomAnimation error code: ${error.code}, message: ${error.message}` ); 3645} 3646``` 3647 3648## ExtensionWindowAttribute<sup>14+</sup> 3649 3650扩展窗口的属性枚举。 3651 3652**模型约束:** 此接口仅可在Stage模型下使用。 3653 3654**系统接口:** 此接口为系统接口。 3655 3656**系统能力:** SystemCapability.Window.SessionManager 3657 3658| 名称 | 值 | 说明 | 3659| ---------- | ----- | ----------- | 3660| SYSTEM_WINDOW | 0 | 系统窗口。| 3661| SUB_WINDOW | 1 | 子窗口。| 3662 3663## SystemWindowOptions<sup>14+</sup> 3664 3665系统窗口的创建参数。 3666 3667**模型约束:** 此接口仅可在Stage模型下使用。 3668 3669**系统接口:** 此接口为系统接口。 3670 3671**系统能力:** SystemCapability.Window.SessionManager 3672 3673| 名称 | 类型 | 只读 |可选 | 说明 | 3674| ------ | ------------------------- | ---- | ---- |---------- | 3675| windowType | [WindowType](#windowtype7) | 否 | 否 | 窗口类型。无默认类型,不配置会导致窗口创建失败。不支持TYPE_DIALOG类型。 | 3676 3677## ExtensionWindowConfig<sup>14+</sup> 3678 3679创建扩展窗口时需要配置的参数。 3680 3681**模型约束:** 此接口仅可在Stage模型下使用。 3682 3683**系统接口:** 此接口为系统接口。 3684 3685**系统能力:** SystemCapability.Window.SessionManager 3686 3687| 名称 | 类型 | 只读 |可选 | 说明 | 3688| ------ | ------------------------- | ---- | ---- |---------- | 3689| windowName | string | 否 | 否 | 窗口名。 | 3690| windowAttribute | [ExtensionWindowAttribute](#extensionwindowattribute14) | 否 | 否 | 窗口的属性。用于配置创建的窗口是子窗口还是系统窗口。当windowAttribute配置为SUB_WINDOW时须配置subWindowOptions,当windowAttribute配置为SYSTEM_WINDOW时须配置systemWindowOptions,否则创建窗口失败。| 3691| windowRect | [Rect](js-apis-window.md#rect7) | 否 | 否 | 窗口矩形区域。 | 3692| subWindowOptions | [SubWindowOptions](js-apis-window.md#subwindowoptions11) | 否 | 是 | 创建子窗口的参数。无默认参数,当windowAttribute配置为SUB_WINDOW时必选,否则会导致窗口创建失败。 | 3693| systemWindowOptions | [SystemWindowOptions](#systemwindowoptions14) | 否 | 是 | 创建系统窗口的参数。无默认参数,当windowAttribute配置为SYSTEM_WINDOW时必选,否则会导致窗口创建失败。 |