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