1# @ohos.window (窗口) 2 3窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。 4 5该模块提供以下窗口相关的常用功能: 6 7- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。 8- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。 9 10> **说明:** 11> 12> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 13 14## 导入模块 15 16```js 17import window from '@ohos.window'; 18``` 19 20## WindowType<sup>7+</sup> 21 22窗口类型枚举。 23 24**系统能力:** SystemCapability.WindowManager.WindowManager.Core 25 26| 名称 | 值 | 说明 | 27| ----------------- | ------ | ------------------ | 28| TYPE_APP | 0 | 表示应用子窗口。<br>**模型约束:** 此接口仅可在FA模型下使用。 | 29| TYPE_SYSTEM_ALERT | 1 | 表示系统告警窗口。 | 30| TYPE_INPUT_METHOD<sup>9+</sup> | 2 | 表示输入法窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 31| TYPE_STATUS_BAR<sup>9+</sup> | 3 | 表示状态栏窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 32| TYPE_PANEL<sup>9+</sup> | 4 | 表示通知栏。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 33| TYPE_KEYGUARD<sup>9+</sup> | 5 | 表示锁屏。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 34| TYPE_VOLUME_OVERLAY<sup>9+</sup> | 6 | 表示音量条。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 35| TYPE_NAVIGATION_BAR<sup>9+</sup> | 7 | 表示导航栏窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 36| TYPE_FLOAT<sup>9+</sup> | 8 | 表示悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**需要权限:** ohos.permission.SYSTEM_FLOAT_WINDOW | 37| TYPE_WALLPAPER<sup>9+</sup> | 9 | 表示壁纸。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 38| TYPE_DESKTOP<sup>9+</sup> | 10 | 表示桌面。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 39| TYPE_LAUNCHER_RECENT<sup>9+</sup> | 11 | 表示多任务中心。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 40| TYPE_LAUNCHER_DOCK<sup>9+</sup> | 12 | 表示桌面Dock栏。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 41| TYPE_VOICE_INTERACTION<sup>9+</sup> | 13 | 表示智慧语音。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 42| TYPE_POINTER<sup>9+</sup> | 14 | 表示鼠标。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 43| TYPE_FLOAT_CAMERA<sup>9+</sup> | 15 | 表示相机类型悬浮窗。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 44| TYPE_DIALOG<sup>9+</sup> | 16 | 表示模态窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 45| TYPE_SCREENSHOT<sup>9+</sup> | 17 | 表示截屏窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。<br>**系统接口:** 此接口为系统接口。 | 46 47## Configuration<sup>9+</sup> 48 49创建子窗口或系统窗口时的参数。 50 51**系统能力:** SystemCapability.WindowManager.WindowManager.Core 52 53| 名称 | 类型 | 必填 | 说明 | 54| ---------- | -------------------------- | -- | ----------------------------------- | 55| name | string | 是 | 窗口名字。 | 56| windowType | [WindowType](#windowtype7) | 是 | 窗口类型。 | 57| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 否 | 当前应用上下文信息。不设置,则默认为空。<br>FA模型下不需要使用该参数,即可创建子窗口。<br>Stage模型下需要使用该参数,用于创建系统窗口。 | 58| displayId | number | 否 | 当前物理屏幕id。不设置,则默认为-1。 | 59| parentId | number | 否 | 父窗口id。不设置,则默认为-1。 | 60 61## AvoidAreaType<sup>7+</sup> 62 63窗口内容需要规避区域的类型枚举。 64 65**系统能力:** SystemCapability.WindowManager.WindowManager.Core 66 67| 名称 | 值 | 说明 | 68| -------------------------------- | ---- | ------------------------------------------------------------ | 69| TYPE_SYSTEM | 0 | 表示系统默认区域。一般包括状态栏、导航栏和Dock栏,各设备系统定义可能不同。 | 70| TYPE_CUTOUT | 1 | 表示刘海屏区域。 | 71| TYPE_SYSTEM_GESTURE<sup>9+</sup> | 2 | 表示手势区域。 | 72| TYPE_KEYBOARD<sup>9+</sup> | 3 | 表示软键盘区域。 | 73 74## WindowMode<sup>7+</sup> 75 76窗口模式枚举。 77 78**系统接口:** 此接口为系统接口。 79 80**系统能力:** SystemCapability.WindowManager.WindowManager.Core 81 82| 名称 | 值 | 说明 | 83| ---------- | ---- | ----------------------------- | 84| UNDEFINED | 1 | 表示APP未定义窗口模式。 | 85| FULLSCREEN | 2 | 表示APP全屏模式。 | 86| PRIMARY | 3 | 表示APP分屏多窗口主要模式。 | 87| SECONDARY | 4 | 表示APP分屏多窗口次要模式。 | 88| FLOATING | 5 | 表示APP自由悬浮形式窗口模式。 | 89 90## WindowLayoutMode<sup>9+</sup> 91 92窗口布局模式枚举。 93 94**系统接口:** 此接口为系统接口。 95 96**系统能力:** SystemCapability.WindowManager.WindowManager.Core 97 98| 名称 | 值 | 说明 | 99| ---------- | ---- | ----------------------------- | 100| WINDOW_LAYOUT_MODE_CASCADE | 0 | 表示使用层叠布局模式。 | 101| WINDOW_LAYOUT_MODE_TILE | 1 | 表示使用平铺布局模式。 | 102 103## SystemBarProperties 104 105状态栏、导航栏的属性。 106 107**系统能力:** SystemCapability.WindowManager.WindowManager.Core 108 109| 名称 | 类型 | 必填 | 说明 | 110| -------------------------------------- | -------- | ---- | ------------------------------------------------------------ | 111| statusBarColor | string | 否 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。默认值:`#0x66000000`。 | 112| isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 状态栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 | 113| statusBarContentColor<sup>8+</sup> | string | 否 | 状态栏文字颜色。当设置此属性后, `isStatusBarLightIcon`属性设置无效。默认值:`0xE5FFFFFF。` | 114| navigationBarColor | string | 否 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。默认值:`#0x66000000。` | 115| isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | 导航栏图标是否为高亮状态。true表示高亮;false表示不高亮。默认值:false。 | 116| navigationBarContentColor<sup>8+</sup> | string | 否 | 导航栏文字颜色。当设置此属性后, `isNavigationBarLightIcon`属性设置无效。默认值:`#0xE5FFFFFF。` | 117 118## Orientation<sup>9+</sup> 119 120窗口显示方向类型枚举。 121 122**系统能力:** SystemCapability.WindowManager.WindowManager.Core 123 124| 名称 | 值 | 说明 | 125| ------------------------------------- | ---- | ----------------------------- | 126| UNSPECIFIED | 0 | 表示未定义方向模式,由系统判定。 | 127| PORTRAIT | 1 | 表示竖屏显示模式。 | 128| LANDSCAPE | 2 | 表示横屏显示模式。 | 129| PORTRAIT_INVERTED | 3 | 表示反向竖屏显示模式。 | 130| LANDSCAPE_INVERTED | 4 | 表示反向横屏显示模式。 | 131| AUTO_ROTATION | 5 | 表示传感器自动旋转模式。 | 132| AUTO_ROTATION_PORTRAIT | 6 | 表示传感器自动竖向旋转模式。 | 133| AUTO_ROTATION_LANDSCAPE | 7 | 表示传感器自动横向旋转模式。 | 134| AUTO_ROTATION_RESTRICTED | 8 | 表示受开关控制的自动旋转模式。 | 135| AUTO_ROTATION_PORTRAIT_RESTRICTED | 9 | 表示受开关控制的自动竖向旋转模式。 | 136| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | 表述受开关控制的自动横向旋转模式。 | 137| LOCKED | 11 | 表示锁定模式。 | 138 139## BlurStyle<sup>9+</sup> 140 141窗口模糊类型枚举。 142 143**系统接口:** 此接口为系统接口。 144 145**系统能力:** SystemCapability.WindowManager.WindowManager.Core 146 147| 名称 | 值 | 说明 | 148| ------- | ---- | -------------------- | 149| OFF | 0 | 表示关闭模糊。 | 150| THIN | 1 | 表示较薄的模糊类型。 | 151| REGULAR | 2 | 表示适中的模糊类型。 | 152| THICK | 3 | 表示较厚的模糊类型。 | 153 154## SystemBarRegionTint<sup>8+</sup> 155 156单个导航栏或状态栏回调信息。 157 158**系统接口:** 此接口为系统接口。 159 160**系统能力:** SystemCapability.WindowManager.WindowManager.Core 161 162| 名称 | 类型 | 可读 | 可写 | 说明 | 163| --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | 164| type | [WindowType](#windowtype7) | 是 | 否 | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 | 165| isEnable | boolean | 是 | 否 | 当前系统栏是否显示。true表示显示;false表示不显示。 | 166| region | [Rect](#rect7) | 是 | 否 | 当前系统栏的位置及大小。 | 167| backgroundColor | string | 是 | 否 | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 168| contentColor | string | 是 | 否 | 系统栏文字颜色。 | 169 170## SystemBarTintState<sup>8+</sup> 171 172当前系统栏回调信息集合。 173 174**系统接口:** 此接口为系统接口。 175 176**系统能力:** SystemCapability.WindowManager.WindowManager.Core 177 178| 名称 | 类型 | 可读 | 可写 | 说明 | 179| ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- | 180| displayId | number | 是 | 否 | 当前物理屏幕id。 | 181| regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | 否 | 当前已改变的所有系统栏信息。 | 182 183## Rect<sup>7+</sup> 184 185窗口矩形区域。 186 187**系统能力:** SystemCapability.WindowManager.WindowManager.Core 188 189| 名称 | 类型 | 可读 | 可写 | 说明 | 190| ------ | -------- | ---- | ---- | ------------------ | 191| left | number | 是 | 是 | 矩形区域的左边界,单位为px。 | 192| top | number | 是 | 是 | 矩形区域的上边界,单位为px。 | 193| width | number | 是 | 是 | 矩形区域的宽度,单位为px。 | 194| height | number | 是 | 是 | 矩形区域的高度,单位为px。 | 195 196## AvoidArea<sup>7+</sup> 197 198窗口内容规避区域。 199 200**系统能力:** SystemCapability.WindowManager.WindowManager.Core 201 202| 名称 | 类型 | 可读 | 可写 | 说明 | 203| ---------- | ------------- | ---- | ---- | ------------------ | 204| visible<sup>9+</sup> | boolean | 是 | 是 | 规避区域是否可见。true表示可见;false表示不可见。 | 205| leftRect | [Rect](#rect7) | 是 | 是 | 屏幕左侧的矩形区。 | 206| topRect | [Rect](#rect7) | 是 | 是 | 屏幕顶部的矩形区。 | 207| rightRect | [Rect](#rect7) | 是 | 是 | 屏幕右侧的矩形区。 | 208| bottomRect | [Rect](#rect7) | 是 | 是 | 屏幕底部的矩形区。 | 209 210## Size<sup>7+</sup> 211 212窗口大小。 213 214**系统能力:** SystemCapability.WindowManager.WindowManager.Core 215 216| 名称 | 类型 | 可读 | 可写 | 说明 | 217| ------ | -------- | ---- | ---- | ---------- | 218| width | number | 是 | 是 | 窗口宽度,单位为px。 | 219| height | number | 是 | 是 | 窗口高度,单位为px。 | 220 221## WindowProperties 222 223窗口属性。 224 225**系统能力:** SystemCapability.WindowManager.WindowManager.Core 226 227| 名称 | 类型 | 可读 | 可写 | 说明 | 228| ------------------------------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | 229| windowRect<sup>7+</sup> | [Rect](#rect7) | 是 | 是 | 窗口尺寸。 | 230| type<sup>7+</sup> | [WindowType](#windowtype7) | 是 | 是 | 窗口类型。 | 231| isFullScreen | boolean | 是 | 是 | 是否全屏,默认为false。true表示全屏;false表示非全屏。 | 232| isLayoutFullScreen<sup>7+</sup> | boolean | 是 | 是 | 窗口是否为沉浸式,默认为false。true表示沉浸式;false表示非沉浸式。 | 233| focusable<sup>7+</sup> | boolean | 是 | 否 | 窗口是否可聚焦,默认为true。true表示可聚焦;false表示不可聚焦。 | 234| touchable<sup>7+</sup> | boolean | 是 | 否 | 窗口是否可触摸,默认为true。true表示可触摸;false表示不可触摸。 | 235| brightness | number | 是 | 是 | 屏幕亮度, 取值范围为0~1,1表示最大亮度值。 | 236| dimBehindValue<sup>(deprecated)</sup> | number | 是 | 是 | 靠后窗口的暗度值,取值范围为0~1,1表示最暗。<br>- **说明:** 从API version 9开始废弃。<br>- 从 API version 7开始支持。 | 237| isKeepScreenOn | boolean | 是 | 是 | 屏幕是否常亮,默认为false。true表示常亮;false表示不常亮。 | 238| isPrivacyMode<sup>7+</sup> | boolean | 是 | 是 | 隐私模式,默认为false。true表示模式开启;false表示模式关闭。 | 239| isRoundCorner<sup>(deprecated)</sup> | boolean | 是 | 是 | 窗口是否为圆角。默认为false。true表示圆角;false表示非圆角。<br>- **说明:** 从API version 9开始废弃。<br/>- 从 API version 7开始支持。 | 240| isTransparent<sup>7+</sup> | boolean | 是 | 是 | 窗口是否透明。默认为false。true表示透明;false表示不透明。 | 241| id<sup>9+</sup> | number | 是 | 否 | 窗口ID,默认值为0.0。 | 242 243## ColorSpace<sup>8+</sup> 244 245色域模式。 246 247**系统能力:** SystemCapability.WindowManager.WindowManager.Core 248 249| 名称 | 值 | 说明 | 250| ---------- | ------ | -------------- | 251| DEFAULT | 0 | 默认SRGB色域模式。 | 252| WIDE_GAMUT | 1 | 广色域模式。 | 253 254## ScaleOptions<sup>9+</sup> 255 256缩放参数。 257 258**系统接口:** 此接口为系统接口。 259 260**系统能力**:SystemCapability.WindowManager.WindowManager.Core 261 262| 名称 | 类型 | 可读 | 可写 | 说明 | 263| ------ | -------- | ---- | ---- | -------------------------------------------------- | 264| x | number | 否 | 是 | X轴的缩放参数,默认值为1.0。 | 265| y | number | 否 | 是 | Y轴的缩放参数,默认值为1.0。 | 266| pivotX | number | 否 | 是 | 缩放中心点X轴坐标,默认值为0.5, 取值范围0.0~1.0。 | 267| pivotY | number | 否 | 是 | 缩放中心点Y轴坐标,默认值为0.5, 取值范围0.0~1.0。 | 268 269## RotateOptions<sup>9+</sup> 270 271旋转参数。 272 273**系统接口:** 此接口为系统接口。 274 275**系统能力**:SystemCapability.WindowManager.WindowManager.Core 276 277| 名称 | 类型 | 可读 | 可写 | 说明 | 278| ------ | -------- | ---- | ---- | -------------------------------------------------- | 279| x | number | 否 | 是 | 绕X轴的旋转角度,默认值为0.0。 | 280| y | number | 否 | 是 | 绕Y轴的旋转角度,默认值为0.0。 | 281| z | number | 否 | 是 | 绕Z轴的旋转角度,默认值为0.0。 | 282| pivotX | number | 否 | 是 | 旋转中心点X轴坐标,默认值为0.5, 取值范围0.0~1.0。 | 283| pivotY | number | 否 | 是 | 旋转中心点Y轴坐标,默认值为0.5, 取值范围0.0~1.0。 | 284 285## TranslateOptions<sup>9+</sup> 286 287平移参数。 288 289**系统接口:** 此接口为系统接口。 290 291**系统能力**:SystemCapability.WindowManager.WindowManager.Core 292 293| 名称 | 类型 | 可读 | 可写 | 说明 | 294| ---- | -------- | ---- | ---- | ---------------------------- | 295| x | number | 否 | 是 | X轴的平移参数,默认值为0.0。 | 296| y | number | 否 | 是 | Y轴的平移参数,默认值为0.0。 | 297| z | number | 否 | 是 | Z轴的平移参数,默认值为0.0。 | 298 299## window.createWindow<sup>9+</sup> 300 301createWindow(config: Configuration, callback: AsyncCallback<Window>): void 302 303创建子窗口或者系统窗口,使用callback异步回调。 304 305**系统能力:** SystemCapability.WindowManager.WindowManager.Core 306 307**参数:** 308 309| 参数名 | 类型 | 必填 | 说明 | 310| -------- | -------------------------------------- | -- | --------------------------------- | 311| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 312| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的窗口对象。 | 313 314**错误码:** 315 316以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 317 318| 错误码ID | 错误信息 | 319| ------- | -------------------------------- | 320| 1300001 | Repeated operation. | 321| 1300006 | This window context is abnormal. | 322 323**示例:** 324 325```js 326let windowClass = null; 327let config = {name: "alertWindow", windowType: window.WindowType.TYPE_SYSTEM_ALERT, ctx: this.context}; 328try { 329 window.createWindow(config, (err, data) => { 330 if (err.code) { 331 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 332 return; 333 } 334 windowClass = data; 335 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 336 windowClass.resetSize(500, 1000); 337 }); 338} catch (exception) { 339 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 340} 341``` 342 343## window.createWindow<sup>9+</sup> 344 345createWindow(config: Configuration): Promise<Window> 346 347创建子窗口或者系统窗口,使用Promise异步回调。 348 349**系统能力:** SystemCapability.WindowManager.WindowManager.Core 350 351**参数:** 352 353| 参数名 | 类型 | 必填 | 说明 | 354| ------ | -------------------------------- | -- | ------------------ | 355| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 356 357**返回值:** 358 359| 类型 | 说明 | 360| -------------------------------- | ------------------------------------ | 361| Promise<[Window](#window)> | Promise对象。返回当前创建的窗口对象。 | 362 363**错误码:** 364 365以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 366 367| 错误码ID | 错误信息 | 368| ------- | -------------------------------- | 369| 1300001 | Repeated operation. | 370| 1300006 | This window context is abnormal. | 371 372**示例:** 373 374```js 375let windowClass = null; 376let config = {name: "alertWindow", windowType: window.WindowType.TYPE_SYSTEM_ALERT, ctx: this.context}; 377try { 378 let promise = window.createWindow(config); 379 promise.then((data)=> { 380 windowClass = data; 381 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 382 }).catch((err)=>{ 383 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 384 }); 385} catch (exception) { 386 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 387} 388``` 389 390## window.findWindow<sup>9+</sup> 391 392findWindow(name: string): Window 393 394查找name所对应的窗口。 395 396**系统能力:** SystemCapability.WindowManager.WindowManager.Core 397 398**参数:** 399 400| 参数名 | 类型 | 必填 | 说明 | 401| ------ | ------ | ---- | -------- | 402| name | string | 是 | 窗口id。 | 403 404**返回值:** 405 406| 类型 | 说明 | 407| ----------------- | ------------------- | 408| [Window](#window) | 当前查找的窗口对象。 | 409 410**示例:** 411 412```js 413let windowClass = null; 414try { 415 windowClass = window.findWindow('alertWindow'); 416} catch (exception) { 417 console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception)); 418} 419``` 420 421## window.getLastWindow<sup>9+</sup> 422 423getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 424 425获取当前应用内最后显示的窗口,使用callback异步回调。 426 427**系统能力:** SystemCapability.WindowManager.WindowManager.Core 428 429**参数:** 430 431| 参数名 | 类型 | 必填 | 说明 | 432| -------- | -------------------------------------- | -- | ---------------------------------------- | 433| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 434| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 435 436**错误码:** 437 438以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 439 440| 错误码ID | 错误信息 | 441| ------- | -------------------------------- | 442| 1300002 | This window state is abnormal. | 443| 1300006 | This window context is abnormal. | 444 445**示例:** 446 447```js 448let windowClass = null; 449try { 450 window.getLastWindow(this.context, (err, data) => { 451 if (err.code) { 452 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 453 return; 454 } 455 windowClass = data; 456 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 457 }); 458} catch (exception) { 459 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 460} 461``` 462 463## window.getLastWindow<sup>9+</sup> 464 465getLastWindow(ctx: BaseContext): Promise<Window> 466 467获取当前应用内最后显示的窗口,使用Promise异步回调。 468 469**系统能力:** SystemCapability.WindowManager.WindowManager.Core 470 471**参数:** 472 473| 参数名 | 类型 | 必填 | 说明 | 474| ------ | ----------- | ---- | ------------------------------------------------------------ | 475| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 476 477**返回值:** 478 479| 类型 | 说明 | 480| -------------------------------- | ------------------------------------------- | 481| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 482 483**错误码:** 484 485以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 486 487| 错误码ID | 错误信息 | 488| ------- | -------------------------------- | 489| 1300002 | This window state is abnormal. | 490| 1300006 | This window context is abnormal. | 491 492**示例:** 493 494```js 495let windowClass = null; 496try { 497 let promise = window.getLastWindow(this.context); 498 promise.then((data)=> { 499 windowClass = data; 500 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 501 }).catch((err)=>{ 502 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 503 }); 504} catch (exception) { 505 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 506} 507``` 508 509## window.minimizeAll<sup>9+</sup> 510minimizeAll(id: number, callback: AsyncCallback<void>): void 511 512最小化某显示设备下的所有窗口。 513 514**系统接口:** 此接口为系统接口。 515 516**系统能力:** SystemCapability.WindowManager.WindowManager.Core 517 518**参数:** 519 520| 参数名 | 类型 | 必填 | 说明 | 521| -------- | ------------------------- | ---- | -------------- | 522| id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号。 | 523| callback | AsyncCallback<void> | 是 | 回调信息。 | 524 525**错误码:** 526 527以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 528 529| 错误码ID | 错误信息 | 530| ------- | -------------------------------------------- | 531| 1300003 | This window manager service works abnormally. | 532 533**示例:** 534 535```js 536import display from '@ohos.display' 537 538let displayClass = null; 539try { 540 displayClass = display.getDefaultDisplaySync(); 541 542 try { 543 window.minimizeAll(displayClass.id, (err) => { 544 if(err.code) { 545 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); 546 return; 547 } 548 console.info('Succeeded in minimizing all windows.'); 549 }); 550 } catch (exception) { 551 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception)); 552 } 553} catch (exception) { 554 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 555} 556``` 557 558## window.minimizeAll<sup>9+</sup> 559minimizeAll(id: number): Promise<void> 560 561最小化某显示设备下的所有窗口。 562 563**系统接口:** 此接口为系统接口。 564 565**系统能力:** SystemCapability.WindowManager.WindowManager.Core 566 567**参数:** 568 569| 参数名 | 类型 | 必填 | 说明 | 570| -------- | ------------------------- | ---- | -------------- | 571| id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号。 | 572 573**返回值:** 574 575| 类型 | 说明 | 576| ------------------- | ------------------------- | 577| Promise<void> | 无返回结果的Promise对象。 | 578 579**错误码:** 580 581以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 582 583| 错误码ID | 错误信息 | 584| ------- | -------------------------------------------- | 585| 1300003 | This window manager service works abnormally. | 586 587**示例:** 588 589```js 590import display from '@ohos.display' 591 592let displayClass = null; 593try { 594 displayClass = display.getDefaultDisplaySync(); 595 596 try { 597 let promise = window.minimizeAll(displayClass.id); 598 promise.then(()=> { 599 console.info('Succeeded in minimizing all windows.'); 600 }).catch((err)=>{ 601 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); 602 }); 603 } catch (exception) { 604 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception)); 605 } 606} catch (exception) { 607 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 608} 609``` 610 611## window.toggleShownStateForAllAppWindows<sup>9+</sup> 612toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void 613 614多窗口快速切换时隐藏或者恢复应用窗口。 615 616**系统接口:** 此接口为系统接口。 617 618**系统能力:** SystemCapability.WindowManager.WindowManager.Core 619 620**参数:** 621 622| 参数名 | 类型 | 必填 | 说明 | 623| -------- | ------------------------- | ---- | -------------- | 624| callback | AsyncCallback<void> | 是 | 回调信息。 | 625 626**错误码:** 627 628以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 629 630| 错误码ID | 错误信息 | 631| ------- | -------------------------------------------- | 632| 1300003 | This window manager service works abnormally. | 633 634**示例:** 635 636```js 637window.toggleShownStateForAllAppWindows((err) => { 638 if (err.code) { 639 console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); 640 return; 641 } 642 console.info('Succeeded in toggling shown state for all app windows.'); 643}); 644``` 645 646## window.toggleShownStateForAllAppWindows<sup>9+</sup> 647toggleShownStateForAllAppWindows(): Promise<void> 648 649多窗口快速切换时隐藏或者恢复应用窗口。 650 651**系统接口:** 此接口为系统接口。 652 653**系统能力:** SystemCapability.WindowManager.WindowManager.Core 654 655**返回值:** 656 657| 类型 | 说明 | 658| ------------------- | ------------------------- | 659| Promise<void> | 无返回结果的Promise对象。 | 660 661**错误码:** 662 663以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 664 665| 错误码ID | 错误信息 | 666| ------- | -------------------------------------------- | 667| 1300003 | This window manager service works abnormally. | 668 669**示例:** 670 671```js 672let promise = window.toggleShownStateForAllAppWindows(); 673promise.then(()=> { 674 console.info('Succeeded in toggling shown state for all app windows.'); 675}).catch((err)=>{ 676 console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); 677}); 678``` 679 680## window.setWindowLayoutMode<sup>9+</sup> 681setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void 682 683设置窗口布局模式。 684 685**系统接口:** 此接口为系统接口。 686 687**系统能力:** SystemCapability.WindowManager.WindowManager.Core 688 689**参数:** 690 691| 参数名 | 类型 | 必填 | 说明 | 692| -------- | ------------------------- | ---- | -------------- | 693| mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | 694| callback | AsyncCallback<void> | 是 | 回调信息。 | 695 696**错误码:** 697 698以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 699 700| 错误码ID | 错误信息 | 701| ------- | -------------------------------------------- | 702| 1300003 | This window manager service works abnormally. | 703 704**示例:** 705 706```js 707try { 708 window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (err) => { 709 if(err.code) { 710 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); 711 return; 712 } 713 console.info('Succeeded in setting window layout mode.'); 714 }); 715} catch (exception) { 716 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception)); 717} 718``` 719 720## window.setWindowLayoutMode<sup>9+</sup> 721setWindowLayoutMode(mode: WindowLayoutMode): Promise<void> 722 723设置窗口布局模式。 724 725**系统接口:** 此接口为系统接口。 726 727**系统能力:** SystemCapability.WindowManager.WindowManager.Core 728 729**参数:** 730 731| 参数名 | 类型 | 必填 | 说明 | 732| -------- | ------------------------- | ---- | -------------- | 733| mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | 734 735**返回值:** 736 737| 类型 | 说明 | 738| ------------------- | ------------------------- | 739| Promise<void> | 无返回结果的Promise对象。 | 740 741**错误码:** 742 743以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 744 745| 错误码ID | 错误信息 | 746| ------- | -------------------------------------------- | 747| 1300003 | This window manager service works abnormally. | 748 749**示例:** 750 751```js 752try { 753 let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE); 754 promise.then(()=> { 755 console.info('Succeeded in setting window layout mode.'); 756 }).catch((err)=>{ 757 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); 758 }); 759} catch (exception) { 760 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception)); 761} 762``` 763 764## window.on('systemBarTintChange')<sup>8+</sup> 765 766on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void 767 768开启状态栏、导航栏属性变化的监听。 769 770**系统接口:** 此接口为系统接口。 771 772**系统能力:** SystemCapability.WindowManager.WindowManager.Core 773 774**参数:** 775 776| 参数名 | 类型 | 必填 | 说明 | 777| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 778| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | 779| callback | Callback<[SystemBarTintState](#systembartintstate8)> | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 | 780 781**示例:** 782 783```js 784try { 785 window.on('systemBarTintChange', (data) => { 786 console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data)); 787 }); 788} catch (exception) { 789 console.error('Failed to enable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception)); 790} 791``` 792 793## window.off('systemBarTintChange')<sup>8+</sup> 794 795off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void 796 797关闭状态栏、导航栏属性变化的监听。 798 799**系统接口:** 此接口为系统接口。 800 801**系统能力:** SystemCapability.WindowManager.WindowManager.Core 802 803**参数:** 804 805| 参数名 | 类型 | 必填 | 说明 | 806| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 807| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | 808| callback | Callback<[SystemBarTintState](#systembartintstate8)> | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。 | 809 810**示例:** 811 812```js 813try { 814 window.off('systemBarTintChange'); 815} catch (exception) { 816 console.error('Failed to disable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception)); 817} 818``` 819 820## window.create<sup>(deprecated)</sup> 821 822create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 823 824创建子窗口,使用callback异步回调。 825 826> **说明:** 827> 828> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 829 830**模型约束:** 此接口仅可在FA模型下使用。 831 832**系统能力:** SystemCapability.WindowManager.WindowManager.Core 833 834**参数:** 835 836| 参数名 | 类型 | 必填 | 说明 | 837| -------- | -------------------------------------- | ---- | ------------------------------------ | 838| id | string | 是 | 窗口id。 | 839| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 840| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 841 842**示例:** 843 844```js 845let windowClass = null; 846window.create('first', window.WindowType.TYPE_APP,(err,data) => { 847 if(err.code){ 848 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 849 return; 850 } 851 windowClass = data; 852 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 853}); 854``` 855 856## window.create<sup>(deprecated)</sup> 857 858create(id: string, type: WindowType): Promise<Window> 859 860创建子窗口,使用Promise异步回调。 861 862> **说明:** 863> 864> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 865 866**模型约束:** 此接口仅可在FA模型下使用。 867 868**系统能力:** SystemCapability.WindowManager.WindowManager.Core 869 870**参数:** 871 872| 参数名 | 类型 | 必填 | 说明 | 873| ------ | ------------------------- | ---- | ---------- | 874| id | string | 是 | 窗口id。 | 875| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 876 877**返回值:** 878 879| 类型 | 说明 | 880| -------------------------------- | --------------------------------------- | 881| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 882 883**示例:** 884 885```js 886let windowClass = null; 887let promise = window.create('first', window.WindowType.TYPE_APP); 888promise.then((data)=> { 889 windowClass = data; 890 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 891}).catch((err)=>{ 892 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 893}); 894``` 895 896## window.create<sup>(deprecated)</sup> 897 898create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 899 900创建系统窗口,使用callback异步回调。 901 902> **说明:** 903> 904> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 905 906**系统能力:** SystemCapability.WindowManager.WindowManager.Core 907 908**参数:** 909 910| 参数名 | 类型 | 必填 | 说明 | 911| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 912| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 913| id | string | 是 | 窗口id。 | 914| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 915| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 916 917**示例:** 918 919```js 920let windowClass = null; 921window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => { 922 if (err.code) { 923 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 924 return; 925 } 926 windowClass = data; 927 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 928 windowClass.resetSize(500, 1000); 929}); 930``` 931 932## window.create<sup>(deprecated)</sup> 933 934create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 935 936创建系统窗口,使用Promise异步回调。 937 938> **说明:** 939> 940> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 941 942**系统能力:** SystemCapability.WindowManager.WindowManager.Core 943 944**参数:** 945 946| 参数名 | 类型 | 必填 | 说明 | 947| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 948| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 949| id | string | 是 | 窗口id。 | 950| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 951 952**返回值:** 953 954| 类型 | 说明 | 955| -------------------------------- | --------------------------------------- | 956| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 957 958**示例:** 959 960```js 961let windowClass = null; 962let promise = window.create(this.context, 'alertWindow', window.WindowType.TYPE_SYSTEM_ALERT); 963promise.then((data)=> { 964 windowClass = data; 965 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 966}).catch((err)=>{ 967 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 968}); 969``` 970 971## window.find<sup>(deprecated)</sup> 972 973find(id: string, callback: AsyncCallback<Window>): void 974 975查找id所对应的窗口,使用callback异步回调。 976 977> **说明:** 978> 979> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 980 981**系统能力:** SystemCapability.WindowManager.WindowManager.Core 982 983**参数:** 984 985| 参数名 | 类型 | 必填 | 说明 | 986| -------- | -------------------------------------- | ---- | ------------------------------------ | 987| id | string | 是 | 窗口id。 | 988| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前查找到的窗口对象。 | 989 990**示例:** 991 992```js 993let windowClass = null; 994window.find('alertWindow', (err, data) => { 995 if (err.code) { 996 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 997 return; 998 } 999 windowClass = data; 1000 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1001}); 1002``` 1003 1004## window.find<sup>(deprecated)</sup> 1005 1006find(id: string): Promise<Window> 1007 1008查找id所对应的窗口,使用Promise异步回调。 1009 1010> **说明:** 1011> 1012> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1013 1014**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1015 1016**参数:** 1017 1018| 参数名 | 类型 | 必填 | 说明 | 1019| ------ | ------ | ---- | -------- | 1020| id | string | 是 | 窗口id。 | 1021 1022**返回值:** 1023 1024| 类型 | 说明 | 1025| -------------------------------- | ------------------------------------- | 1026| Promise<[Window](#window)> | Promise对象。返回当前查找的窗口对象。 | 1027 1028**示例:** 1029 1030```js 1031let windowClass = null; 1032let promise = window.find('alertWindow'); 1033promise.then((data)=> { 1034 windowClass = data; 1035 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1036}).catch((err)=>{ 1037 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 1038}); 1039``` 1040 1041## window.getTopWindow<sup>(deprecated)</sup> 1042 1043getTopWindow(callback: AsyncCallback<Window>): void 1044 1045获取当前应用内最后显示的窗口,使用callback异步回调。 1046 1047> **说明:** 1048> 1049> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1050 1051**模型约束:** 此接口仅可在FA模型下使用。 1052 1053**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1054 1055**参数:** 1056 1057| 参数名 | 类型 | 必填 | 说明 | 1058| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1059| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1060 1061**示例:** 1062 1063```js 1064let windowClass = null; 1065window.getTopWindow((err, data) => { 1066 if (err.code) { 1067 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1068 return; 1069 } 1070 windowClass = data; 1071 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1072}); 1073``` 1074 1075## window.getTopWindow<sup>(deprecated)</sup> 1076 1077getTopWindow(): Promise<Window> 1078 1079获取当前应用内最后显示的窗口,使用Promise异步回调。 1080 1081> **说明:** 1082> 1083> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1084 1085**模型约束:** 此接口仅可在FA模型下使用。 1086 1087**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1088 1089**返回值:** 1090 1091| 类型 | 说明 | 1092| -------------------------------- | ----------------------------------------------- | 1093| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1094 1095**示例:** 1096 1097```js 1098let windowClass = null; 1099let promise = window.getTopWindow(); 1100promise.then((data)=> { 1101 windowClass = data; 1102 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1103}).catch((err)=>{ 1104 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1105}); 1106``` 1107 1108## window.getTopWindow<sup>(deprecated)</sup> 1109 1110getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1111 1112获取当前应用内最后显示的窗口,使用callback异步回调。 1113 1114> **说明:** 1115> 1116> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1117 1118**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1119 1120**参数:** 1121 1122| 参数名 | 类型 | 必填 | 说明 | 1123| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1124| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1125| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1126 1127**示例:** 1128 1129```js 1130let windowClass = null; 1131window.getTopWindow(this.context, (err, data) => { 1132 if (err.code) { 1133 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1134 return; 1135 } 1136 windowClass = data; 1137 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1138}); 1139``` 1140 1141## window.getTopWindow<sup>(deprecated)</sup> 1142 1143getTopWindow(ctx: BaseContext): Promise<Window> 1144 1145获取当前应用内最后显示的窗口,使用Promise异步回调。 1146 1147> **说明:** 1148> 1149> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1150 1151**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1152 1153**参数:** 1154 1155| 参数名 | 类型 | 必填 | 说明 | 1156| ------ | ----------- | ---- | ------------------------------------------------------------ | 1157| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1158 1159**返回值:** 1160 1161| 类型 | 说明 | 1162| -------------------------------- | ----------------------------------------------- | 1163| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1164 1165**示例:** 1166 1167```js 1168let windowClass = null; 1169let promise = window.getTopWindow(this.context); 1170promise.then((data)=> { 1171 windowClass = data; 1172 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1173}).catch((err)=>{ 1174 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1175}); 1176``` 1177 1178## Window 1179 1180当前窗口实例,窗口管理器管理的基本单元。 1181 1182下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例,再通过此实例调用对应方法。 1183 1184### hide<sup>7+</sup> 1185 1186hide (callback: AsyncCallback<void>): void 1187 1188隐藏当前窗口,使用callback异步回调。 1189 1190**系统接口:** 此接口为系统接口。 1191 1192**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1193 1194**参数:** 1195 1196| 参数名 | 类型 | 必填 | 说明 | 1197| -------- | ------------------------- | ---- | ---------- | 1198| callback | AsyncCallback<void> | 是 | 回调函数。 | 1199 1200**错误码:** 1201 1202以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1203 1204| 错误码ID | 错误信息 | 1205| ------- | ------------------------------ | 1206| 1300002 | This window state is abnormal. | 1207 1208**示例:** 1209 1210```js 1211windowClass.hide((err) => { 1212 if (err.code) { 1213 console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); 1214 return; 1215 } 1216 console.info('Succeeded in hiding the window.'); 1217}); 1218``` 1219 1220### hide<sup>7+</sup> 1221 1222hide(): Promise<void> 1223 1224隐藏当前窗口,使用Promise异步回调。 1225 1226**系统接口:** 此接口为系统接口。 1227 1228**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1229 1230**返回值:** 1231 1232| 类型 | 说明 | 1233| ------------------- | ------------------------- | 1234| Promise<void> | 无返回结果的Promise对象。 | 1235 1236**错误码:** 1237 1238以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1239 1240| 错误码ID | 错误信息 | 1241| ------- | ------------------------------ | 1242| 1300002 | This window state is abnormal. | 1243 1244**示例:** 1245 1246```js 1247let promise = windowClass.hide(); 1248promise.then(()=> { 1249 console.info('Succeeded in hiding the window.'); 1250}).catch((err)=>{ 1251 console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); 1252}); 1253``` 1254 1255### hideWithAnimation<sup>9+</sup> 1256 1257hideWithAnimation(callback: AsyncCallback<void>): void 1258 1259隐藏当前窗口,过程中播放动画,使用callback异步回调。 1260 1261**系统接口:** 此接口为系统接口。 1262 1263**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1264 1265**参数:** 1266 1267| 参数名 | 类型 | 必填 | 说明 | 1268| -------- | ------------------------- | ---- | ---------- | 1269| callback | AsyncCallback<void> | 是 | 回调函数。 | 1270 1271**错误码:** 1272 1273以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1274 1275| 错误码ID | 错误信息 | 1276| ------- | -------------------------------------------- | 1277| 1300002 | This window state is abnormal. | 1278| 1300003 | This window manager service works abnormally. | 1279| 1300004 | Unauthorized operation. | 1280 1281**示例:** 1282 1283```js 1284windowClass.hideWithAnimation((err) => { 1285 if (err.code) { 1286 console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 1287 return; 1288 } 1289 console.info('Succeeded in hiding the window with animation.'); 1290}); 1291``` 1292 1293### hideWithAnimation<sup>9+</sup> 1294 1295hideWithAnimation(): Promise<void> 1296 1297隐藏当前窗口,过程中播放动画,使用Promise异步回调。 1298 1299**系统接口:** 此接口为系统接口。 1300 1301**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1302 1303**返回值:** 1304 1305| 类型 | 说明 | 1306| ------------------- | ------------------------- | 1307| Promise<void> | 无返回结果的Promise对象。 | 1308 1309**错误码:** 1310 1311以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1312 1313| 错误码ID | 错误信息 | 1314| ------- | -------------------------------------------- | 1315| 1300002 | This window state is abnormal. | 1316| 1300003 | This window manager service works abnormally. | 1317| 1300004 | Unauthorized operation. | 1318 1319**示例:** 1320 1321```js 1322let promise = windowClass.hideWithAnimation(); 1323promise.then(()=> { 1324 console.info('Succeeded in hiding the window with animation.'); 1325}).catch((err)=>{ 1326 console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 1327}); 1328``` 1329 1330### showWindow<sup>9+</sup> 1331 1332showWindow(callback: AsyncCallback<void>): void 1333 1334显示当前窗口,使用callback异步回调。 1335 1336**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1337 1338**参数:** 1339 1340| 参数名 | 类型 | 必填 | 说明 | 1341| -------- | ------------------------- | -- | --------- | 1342| callback | AsyncCallback<void> | 是 | 回调函数。 | 1343 1344**错误码:** 1345 1346以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1347 1348| 错误码ID | 错误信息 | 1349| ------- | ------------------------------ | 1350| 1300002 | This window state is abnormal. | 1351 1352**示例:** 1353 1354```js 1355windowClass.showWindow((err) => { 1356 if (err.code) { 1357 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1358 return; 1359 } 1360 console.info('Succeeded in showing the window.'); 1361}); 1362``` 1363 1364### showWindow<sup>9+</sup> 1365 1366showWindow(): Promise<void> 1367 1368显示当前窗口,使用Promise异步回调。 1369 1370**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1371 1372**返回值:** 1373 1374| 类型 | 说明 | 1375| ------------------- | ----------------------- | 1376| Promise<void> | 无返回结果的Promise对象。 | 1377 1378**错误码:** 1379 1380以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1381 1382| 错误码ID | 错误信息 | 1383| ------- | ------------------------------ | 1384| 1300002 | This window state is abnormal. | 1385 1386**示例:** 1387 1388```js 1389let promise = windowClass.showWindow(); 1390promise.then(()=> { 1391 console.info('Succeeded in showing the window.'); 1392}).catch((err)=>{ 1393 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1394}); 1395``` 1396 1397### showWithAnimation<sup>9+</sup> 1398 1399showWithAnimation(callback: AsyncCallback<void>): void 1400 1401显示当前窗口,过程中播放动画,使用callback异步回调。 1402 1403**系统接口:** 此接口为系统接口。 1404 1405**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1406 1407**参数:** 1408 1409| 参数名 | 类型 | 必填 | 说明 | 1410| -------- | ------------------------- | ---- | ---------- | 1411| callback | AsyncCallback<void> | 是 | 回调函数。 | 1412 1413**错误码:** 1414 1415以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1416 1417| 错误码ID | 错误信息 | 1418| ------- | -------------------------------------------- | 1419| 1300002 | This window state is abnormal. | 1420| 1300003 | This window manager service works abnormally. | 1421| 1300004 | Unauthorized operation. | 1422 1423**示例:** 1424 1425```js 1426windowClass.showWithAnimation((err) => { 1427 if (err.code) { 1428 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 1429 return; 1430 } 1431 console.info('Succeeded in showing the window with animation.'); 1432}); 1433``` 1434 1435### showWithAnimation<sup>9+</sup> 1436 1437showWithAnimation(): Promise<void> 1438 1439显示当前窗口,过程中播放动画,使用Promise异步回调。 1440 1441**系统接口:** 此接口为系统接口。 1442 1443**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1444 1445**返回值:** 1446 1447| 类型 | 说明 | 1448| ------------------- | ------------------------- | 1449| Promise<void> | 无返回结果的Promise对象。 | 1450 1451**错误码:** 1452 1453以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1454 1455| 错误码ID | 错误信息 | 1456| ------- | -------------------------------------------- | 1457| 1300002 | This window state is abnormal. | 1458| 1300003 | This window manager service works abnormally. | 1459| 1300004 | Unauthorized operation. | 1460 1461**示例:** 1462 1463```js 1464let promise = windowClass.showWithAnimation(); 1465promise.then(()=> { 1466 console.info('Succeeded in showing the window with animation.'); 1467}).catch((err)=>{ 1468 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 1469}); 1470``` 1471 1472### destroyWindow<sup>9+</sup> 1473 1474destroyWindow(callback: AsyncCallback<void>): void 1475 1476销毁当前窗口,使用callback异步回调。 1477 1478**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1479 1480**参数:** 1481 1482| 参数名 | 类型 | 必填 | 说明 | 1483| -------- | ------------------------- | -- | --------- | 1484| callback | AsyncCallback<void> | 是 | 回调函数。 | 1485 1486**错误码:** 1487 1488以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1489 1490| 错误码ID | 错误信息 | 1491| ------- | -------------------------------------------- | 1492| 1300002 | This window state is abnormal. | 1493| 1300003 | This window manager service works abnormally. | 1494 1495**示例:** 1496 1497```js 1498windowClass.destroyWindow((err) => { 1499 if (err.code) { 1500 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 1501 return; 1502 } 1503 console.info('Succeeded in destroying the window.'); 1504}); 1505``` 1506 1507### destroyWindow<sup>9+</sup> 1508 1509destroyWindow(): Promise<void> 1510 1511销毁当前窗口,使用Promise异步回调。 1512 1513**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1514 1515**返回值:** 1516 1517| 类型 | 说明 | 1518| ------------------- | ------------------------ | 1519| Promise<void> | 无返回结果的Promise对象。 | 1520 1521**错误码:** 1522 1523以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1524 1525| 错误码ID | 错误信息 | 1526| ------- | -------------------------------------------- | 1527| 1300002 | This window state is abnormal. | 1528| 1300003 | This window manager service works abnormally. | 1529 1530**示例:** 1531 1532```js 1533let promise = windowClass.destroyWindow(); 1534promise.then(()=> { 1535 console.info('Succeeded in destroying the window.'); 1536}).catch((err)=>{ 1537 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 1538}); 1539``` 1540 1541### moveWindowTo<sup>9+</sup> 1542 1543moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 1544 1545移动窗口位置,使用callback异步回调。 1546 1547全屏模式窗口不支持该操作。 1548 1549**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1550 1551**参数:** 1552 1553| 参数名 | 类型 | 必填 | 说明 | 1554| -------- | ------------------------- | -- | --------------------------------------------- | 1555| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px。 | 1556| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px。 | 1557| callback | AsyncCallback<void> | 是 | 回调函数。 | 1558 1559**错误码:** 1560 1561以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1562 1563| 错误码ID | 错误信息 | 1564| ------- | -------------------------------------------- | 1565| 1300002 | This window state is abnormal. | 1566| 1300003 | This window manager service works abnormally. | 1567 1568**示例:** 1569 1570```js 1571try { 1572 windowClass.moveWindowTo(300, 300, (err)=>{ 1573 if (err.code) { 1574 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 1575 return; 1576 } 1577 console.info('Succeeded in moving the window.'); 1578 }); 1579} catch (exception) { 1580 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 1581} 1582``` 1583 1584### moveWindowTo<sup>9+</sup> 1585 1586moveWindowTo(x: number, y: number): Promise<void> 1587 1588移动窗口位置,使用Promise异步回调。 1589 1590全屏模式窗口不支持该操作。 1591 1592**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1593 1594**参数:** 1595 1596| 参数名 | 类型 | 必填 | 说明 | 1597| -- | ----- | -- | --------------------------------------------- | 1598| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px。 | 1599| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px。 | 1600 1601**返回值:** 1602 1603| 类型 | 说明 | 1604| ------------------- | ------------------------ | 1605| Promise<void> | 无返回结果的Promise对象。 | 1606 1607**错误码:** 1608 1609以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1610 1611| 错误码ID | 错误信息 | 1612| ------- | -------------------------------------------- | 1613| 1300002 | This window state is abnormal. | 1614| 1300003 | This window manager service works abnormally. | 1615 1616**示例:** 1617 1618```js 1619try { 1620 let promise = windowClass.moveWindowTo(300, 300); 1621 promise.then(()=> { 1622 console.info('Succeeded in moving the window.'); 1623 }).catch((err)=>{ 1624 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 1625 }); 1626} catch (exception) { 1627 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 1628} 1629``` 1630 1631### resize<sup>9+</sup> 1632 1633resize(width: number, height: number, callback: AsyncCallback<void>): void 1634 1635改变当前窗口大小,使用callback异步回调。 1636 1637应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。 1638 1639系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 1640 1641设置的宽度与高度受到此约束限制。 1642 1643全屏模式窗口不支持该操作。 1644 1645**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1646 1647**参数:** 1648 1649| 参数名 | 类型 | 必填 | 说明 | 1650| -------- | ------------------------- | -- | ------------------------ | 1651| width | number | 是 | 目标窗口的宽度,单位为px。 | 1652| height | number | 是 | 目标窗口的高度,单位为px。 | 1653| callback | AsyncCallback<void> | 是 | 回调函数。 | 1654 1655**错误码:** 1656 1657以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1658 1659| 错误码ID | 错误信息 | 1660| ------- | -------------------------------------------- | 1661| 1300002 | This window state is abnormal. | 1662| 1300003 | This window manager service works abnormally. | 1663 1664**示例:** 1665 1666```js 1667try { 1668 windowClass.resize(500, 1000, (err) => { 1669 if (err.code) { 1670 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 1671 return; 1672 } 1673 console.info('Succeeded in changing the window size.'); 1674 }); 1675} catch (exception) { 1676 console.error('Failed to change the window size. Cause:' + JSON.stringify(exception)); 1677} 1678``` 1679 1680### resize<sup>9+</sup> 1681 1682resize(width: number, height: number): Promise<void> 1683 1684改变当前窗口大小,使用Promise异步回调。 1685 1686应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。 1687 1688系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 1689 1690设置的宽度与高度受到此约束限制。 1691 1692全屏模式窗口不支持该操作。 1693 1694**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1695 1696**参数:** 1697 1698| 参数名 | 类型 | 必填 | 说明 | 1699| ------ | ------ | -- | ------------------------ | 1700| width | number | 是 | 目标窗口的宽度,单位为px。 | 1701| height | number | 是 | 目标窗口的高度,单位为px。 | 1702 1703**返回值:** 1704 1705| 类型 | 说明 | 1706| ------------------- | ------------------------ | 1707| Promise<void> | 无返回结果的Promise对象。 | 1708 1709**错误码:** 1710 1711以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1712 1713| 错误码ID | 错误信息 | 1714| ------- | -------------------------------------------- | 1715| 1300002 | This window state is abnormal. | 1716| 1300003 | This window manager service works abnormally. | 1717 1718**示例:** 1719 1720```js 1721try { 1722 let promise = windowClass.resize(500, 1000); 1723 promise.then(()=> { 1724 console.info('Succeeded in changing the window size.'); 1725 }).catch((err)=>{ 1726 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 1727 }); 1728} catch (exception) { 1729 console.error('Failed to change the window size. Cause: ' + JSON.stringify(exception)); 1730} 1731``` 1732 1733### setWindowMode<sup>9+</sup> 1734 1735setWindowMode(mode: WindowMode, callback: AsyncCallback<void>): void 1736 1737设置窗口模式,使用callback异步回调。 1738 1739**系统接口:** 此接口为系统接口。 1740 1741**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1742 1743**参数:** 1744 1745| 参数名 | 类型 | 必填 | 说明 | 1746| -------- | -------------------------- | -- | --------- | 1747| mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | 1748| callback | AsyncCallback<void> | 是 | 回调函数。 | 1749 1750**错误码:** 1751 1752以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1753 1754| 错误码ID | 错误信息 | 1755| ------- | -------------------------------------------- | 1756| 1300002 | This window state is abnormal. | 1757| 1300003 | This window manager service works abnormally. | 1758 1759**示例:** 1760 1761```js 1762let mode = window.WindowMode.FULLSCREEN; 1763try { 1764 windowClass.setWindowMode(mode, (err) => { 1765 if (err.code) { 1766 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err)); 1767 return; 1768 } 1769 console.info('Succeeded in setting the window mode.'); 1770 }); 1771} catch (exception) { 1772 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception)); 1773} 1774``` 1775 1776### setWindowMode<sup>9+</sup> 1777 1778setWindowMode(mode: WindowMode): Promise<void> 1779 1780设置窗口类型,使用Promise异步回调。 1781 1782**系统接口:** 此接口为系统接口。 1783 1784**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1785 1786**参数:** 1787 1788| 参数名 | 类型 | 必填 | 说明 | 1789| -------- | -------------------------- | -- | --------- | 1790| mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | 1791 1792**返回值:** 1793 1794| 类型 | 说明 | 1795| ------------------- | ----------------------- | 1796| Promise<void> | 无返回结果的Promise对象。 | 1797 1798**错误码:** 1799 1800以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1801 1802| 错误码ID | 错误信息 | 1803| ------- | -------------------------------------------- | 1804| 1300002 | This window state is abnormal. | 1805| 1300003 | This window manager service works abnormally. | 1806 1807**示例:** 1808 1809```js 1810let mode = window.WindowMode.FULLSCREEN; 1811try { 1812 let promise = windowClass.setWindowMode(mode); 1813 promise.then(()=> { 1814 console.info('Succeeded in setting the window mode.'); 1815 }).catch((err)=>{ 1816 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err)); 1817 }); 1818} catch (exception) { 1819 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception)); 1820} 1821``` 1822 1823### getWindowProperties<sup>9+</sup> 1824 1825getWindowProperties(): WindowProperties 1826 1827获取当前窗口的属性,返回WindowProperties。 1828 1829**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1830 1831**返回值:** 1832 1833| 类型 | 说明 | 1834| ------------------------------------- | ------------- | 1835| [WindowProperties](#windowproperties) | 当前窗口属性。 | 1836 1837**错误码:** 1838 1839以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1840 1841| 错误码ID | 错误信息 | 1842| ------- | ------------------------------ | 1843| 1300002 | This window state is abnormal. | 1844 1845**示例:** 1846 1847```js 1848try { 1849 let properties = windowClass.getWindowProperties(); 1850} catch (exception) { 1851 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); 1852} 1853``` 1854 1855### getWindowAvoidArea<sup>9+</sup> 1856 1857getWindowAvoidArea(type: AvoidAreaType): AvoidArea 1858 1859获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 1860 1861**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1862 1863**参数:** 1864 1865| 参数名 | 类型 | 必填 | 说明 | 1866| ---- |----------------------------------| -- | ------------------------------------------------------------ | 1867| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 1868 1869**返回值:** 1870 1871| 类型 | 说明 | 1872|--------------------------| ----------------- | 1873| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 | 1874 1875**错误码:** 1876 1877以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1878 1879| 错误码ID | 错误信息 | 1880| ------- | ------------------------------ | 1881| 1300002 | This window state is abnormal. | 1882 1883**示例:** 1884 1885```js 1886let type = window.AvoidAreaType.TYPE_SYSTEM; 1887try { 1888 let avoidArea = windowClass.getWindowAvoidArea(type); 1889} catch (exception) { 1890 console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception)); 1891} 1892``` 1893 1894### setWindowLayoutFullScreen<sup>9+</sup> 1895 1896setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 1897 1898设置窗口的布局是否为全屏显示状态,使用callback异步回调。 1899 1900**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1901 1902**参数:** 1903 1904| 参数名 | 类型 | 必填 | 说明 | 1905| ------------------ | ------------------------- | -- | --------- | 1906| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为全屏显示状态(该全屏状态下状态栏、导航栏仍然显示)。true表示全屏显示;false表示非全屏显示。 | 1907| callback | AsyncCallback<void> | 是 | 回调函数。 | 1908 1909**错误码:** 1910 1911以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1912 1913| 错误码ID | 错误信息 | 1914| ------- | -------------------------------------------- | 1915| 1300002 | This window state is abnormal. | 1916| 1300003 | This window manager service works abnormally. | 1917 1918**示例:** 1919 1920```js 1921let isLayoutFullScreen= true; 1922try { 1923 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { 1924 if (err.code) { 1925 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 1926 return; 1927 } 1928 console.info('Succeeded in setting the window layout to full-screen mode.'); 1929 }); 1930} catch (exception) { 1931 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 1932} 1933``` 1934 1935### setWindowLayoutFullScreen<sup>9+</sup> 1936 1937setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 1938 1939设置窗口的布局是否为全屏显示状态,使用Promise异步回调。 1940 1941**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1942 1943**参数:** 1944 1945| 参数名 | 类型 | 必填 | 说明 | 1946| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 1947| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为全屏显示状态(该全屏状态下状态栏、导航栏仍然显示)。true表示全屏显示;false表示非全屏显示。 | 1948 1949**返回值:** 1950 1951| 类型 | 说明 | 1952| ------------------- | ------------------------ | 1953| Promise<void> | 无返回结果的Promise对象。 | 1954 1955**错误码:** 1956 1957以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1958 1959| 错误码ID | 错误信息 | 1960| ------- | -------------------------------------------- | 1961| 1300002 | This window state is abnormal. | 1962| 1300003 | This window manager service works abnormally. | 1963 1964**示例:** 1965 1966```js 1967let isLayoutFullScreen = true; 1968try { 1969 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 1970 promise.then(()=> { 1971 console.info('Succeeded in setting the window layout to full-screen mode.'); 1972 }).catch((err)=>{ 1973 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 1974 }); 1975} catch (exception) { 1976 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 1977} 1978``` 1979 1980### setWindowSystemBarEnable<sup>9+</sup> 1981 1982setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 1983 1984设置导航栏、状态栏的可见模式,使用callback异步回调。 1985 1986**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1987 1988**参数:** 1989 1990| 参数名 | 类型 | 必填 | 说明 | 1991| -------- | ---------------------------- | -- | --------- | 1992| names | Array<'status'\|'navigation'> | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 1993| callback | AsyncCallback<void> | 是 | 回调函数。 | 1994 1995**错误码:** 1996 1997以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1998 1999| 错误码ID | 错误信息 | 2000| ------- | -------------------------------------------- | 2001| 1300002 | This window state is abnormal. | 2002| 1300003 | This window manager service works abnormally. | 2003 2004**示例:** 2005 2006```js 2007// 此处以不显示导航栏、状态栏为例 2008let names = []; 2009try { 2010 windowClass.setWindowSystemBarEnable(names, (err) => { 2011 if (err.code) { 2012 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 2013 return; 2014 } 2015 console.info('Succeeded in setting the system bar to be invisible.'); 2016 }); 2017} catch (exception) { 2018 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 2019} 2020``` 2021 2022### setWindowSystemBarEnable<sup>9+</sup> 2023 2024setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2025 2026设置导航栏、状态栏的可见模式,使用Promise异步回调。 2027 2028**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2029 2030**参数:** 2031 2032| 参数名 | 类型 | 必填 | 说明 | 2033| ----- | ---------------------------- | -- | --------------------------------- | 2034| names | Array<'status'\|'navigation'> | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 2035 2036**返回值:** 2037 2038| 类型 | 说明 | 2039| ------------------- | ------------------------ | 2040| Promise<void> | 无返回结果的Promise对象。 | 2041 2042**错误码:** 2043 2044以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2045 2046| 错误码ID | 错误信息 | 2047| ------- | -------------------------------------------- | 2048| 1300002 | This window state is abnormal. | 2049| 1300003 | This window manager service works abnormally. | 2050 2051**示例:** 2052 2053```js 2054// 此处以不显示导航栏、状态栏为例 2055let names = []; 2056try { 2057 let promise = windowClass.setWindowSystemBarEnable(names); 2058 promise.then(()=> { 2059 console.info('Succeeded in setting the system bar to be invisible.'); 2060 }).catch((err)=>{ 2061 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 2062 }); 2063} catch (exception) { 2064 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 2065} 2066``` 2067 2068### setWindowSystemBarProperties<sup>9+</sup> 2069 2070setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 2071 2072设置窗口内导航栏、状态栏的属性,使用callback异步回调。 2073 2074**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2075 2076**参数:** 2077 2078| 参数名 | 类型 | 必填 | 说明 | 2079| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2080| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 2081| callback | AsyncCallback<void> | 是 | 回调函数。 | 2082 2083**错误码:** 2084 2085以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2086 2087| 错误码ID | 错误信息 | 2088| ------- | -------------------------------------------- | 2089| 1300002 | This window state is abnormal. | 2090| 1300003 | This window manager service works abnormally. | 2091 2092**示例:** 2093 2094```js 2095let SystemBarProperties = { 2096 statusBarColor: '#ff00ff', 2097 navigationBarColor: '#00ff00', 2098 //以下两个属性从API Version8开始支持 2099 statusBarContentColor:'#ffffff', 2100 navigationBarContentColor:'#00ffff' 2101}; 2102try { 2103 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err) => { 2104 if (err.code) { 2105 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 2106 return; 2107 } 2108 console.info('Succeeded in setting the system bar properties.'); 2109 }); 2110} catch (exception) { 2111 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 2112} 2113``` 2114 2115### setWindowSystemBarProperties<sup>9+</sup> 2116 2117setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2118 2119设置窗口内导航栏、状态栏的属性,使用Promise异步回调。 2120 2121**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2122 2123**参数:** 2124 2125| 参数名 | 类型 | 必填 | 说明 | 2126| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2127| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 2128 2129**返回值:** 2130 2131| 类型 | 说明 | 2132| ------------------- | ------------------------- | 2133| Promise<void> | 无返回结果的Promise对象。 | 2134 2135**错误码:** 2136 2137以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2138 2139| 错误码ID | 错误信息 | 2140| ------- | -------------------------------------------- | 2141| 1300002 | This window state is abnormal. | 2142| 1300003 | This window manager service works abnormally. | 2143 2144**示例:** 2145 2146```js 2147let SystemBarProperties = { 2148 statusBarColor: '#ff00ff', 2149 navigationBarColor: '#00ff00', 2150 //以下两个属性从API Version8开始支持 2151 statusBarContentColor:'#ffffff', 2152 navigationBarContentColor:'#00ffff' 2153}; 2154try { 2155 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2156 promise.then(()=> { 2157 console.info('Succeeded in setting the system bar properties.'); 2158 }).catch((err)=>{ 2159 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 2160 }); 2161} catch (exception) { 2162 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 2163} 2164``` 2165 2166### setPreferredOrientation<sup>9+</sup> 2167 2168setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2169 2170设置窗口的显示方向属性,使用callback异步回调。 2171 2172**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2173 2174**参数:** 2175 2176| 参数名 | 类型 | 必填 | 说明 | 2177| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2178| Orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2179| callback | AsyncCallback<void> | 是 | 回调函数。 | 2180 2181**错误码:** 2182 2183以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2184 2185| 错误码ID | 错误信息 | 2186| ------- | ------------------------------ | 2187| 1300002 | This window state is abnormal. | 2188 2189**示例:** 2190 2191```js 2192let orientation = window.Orientation.AUTO_ROTATION; 2193try { 2194 windowClass.setPreferredOrientation(orientation, (err) => { 2195 if (err.code) { 2196 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); 2197 return; 2198 } 2199 console.info('Succeeded in setting window orientation.'); 2200 }); 2201} catch (exception) { 2202 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 2203} 2204``` 2205 2206### setPreferredOrientation<sup>9+</sup> 2207 2208setPreferredOrientation(orientation: Orientation): Promise<void> 2209 2210设置窗口的显示方向属性,使用Promise异步回调。 2211 2212**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2213 2214**参数:** 2215 2216| 参数名 | 类型 | 必填 | 说明 | 2217| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2218| Orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2219 2220**返回值:** 2221 2222| 类型 | 说明 | 2223| ------------------- | ------------------------- | 2224| Promise<void> | 无返回结果的Promise对象。 | 2225 2226**错误码:** 2227 2228以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2229 2230| 错误码ID | 错误信息 | 2231| ------- | ------------------------------ | 2232| 1300002 | This window state is abnormal. | 2233 2234**示例:** 2235 2236```js 2237let orientation = window.Orientation.AUTO_ROTATION; 2238try { 2239 let promise = windowClass.setPreferredOrientation(orientation); 2240 promise.then(()=> { 2241 console.info('Succeeded in setting the window orientation.'); 2242 }).catch((err)=>{ 2243 console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err)); 2244 }); 2245} catch (exception) { 2246 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 2247} 2248``` 2249 2250### setUIContent<sup>9+</sup> 2251 2252setUIContent(path: string, callback: AsyncCallback<void>): void 2253 2254为当前窗口加载具体页面内容,使用callback异步回调。 2255 2256**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2257 2258**参数:** 2259 2260| 参数名 | 类型 | 必填 | 说明 | 2261| -------- | ------------------------- | -- | -------------------- | 2262| path | string | 是 | 设置加载页面的路径。 | 2263| callback | AsyncCallback<void> | 是 | 回调函数。 | 2264 2265**错误码:** 2266 2267以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2268 2269| 错误码ID | 错误信息 | 2270| ------- | -------------------------------------------- | 2271| 1300002 | This window state is abnormal. | 2272| 1300003 | This window manager service works abnormally. | 2273 2274**示例:** 2275 2276```js 2277try { 2278 windowClass.setUIContent('pages/page2/page2', (err) => { 2279 if (err.code) { 2280 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2281 return; 2282 } 2283 console.info('Succeeded in loading the content.'); 2284 }); 2285} catch (exception) { 2286 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2287} 2288``` 2289 2290### setUIContent<sup>9+</sup> 2291 2292setUIContent(path: string): Promise<void> 2293 2294为当前窗口加载具体页面内容,使用Promise异步回调。 2295 2296**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2297 2298**参数:** 2299 2300| 参数名 | 类型 | 必填 | 说明 | 2301| ---- | ------ | -- | ------------------ | 2302| path | string | 是 | 设置加载页面的路径。 | 2303 2304**返回值:** 2305 2306| 类型 | 说明 | 2307| ------------------- | ------------------------ | 2308| Promise<void> | 无返回结果的Promise对象。 | 2309 2310**错误码:** 2311 2312以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2313 2314| 错误码ID | 错误信息 | 2315| ------- | -------------------------------------------- | 2316| 1300002 | This window state is abnormal. | 2317| 1300003 | This window manager service works abnormally. | 2318 2319**示例:** 2320 2321```js 2322try { 2323 let promise = windowClass.setUIContent('pages/page2/page2'); 2324 promise.then(()=> { 2325 console.info('Succeeded in loading the content.'); 2326 }).catch((err)=>{ 2327 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 2328 }); 2329} catch (exception) { 2330 console.error('Failed to load the content. Cause: ' + JSON.stringify(exception)); 2331} 2332``` 2333 2334### loadContent<sup>9+</sup> 2335 2336loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2337 2338为当前窗口加载与LocalStorage相关联的具体页面内容,使用callback异步回调。 2339 2340**模型约束:** 此接口仅可在Stage模型下使用。 2341 2342**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2343 2344**参数:** 2345 2346| 参数名 | 类型 | 必填 | 说明 | 2347| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2348| path | string | 是 | 设置加载页面的路径。 | 2349| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 | 2350| callback | AsyncCallback<void> | 是 | 回调函数。 | 2351 2352**错误码:** 2353 2354以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2355 2356| 错误码ID | 错误信息 | 2357| ------- | -------------------------------------------- | 2358| 1300002 | This window state is abnormal. | 2359| 1300003 | This window manager service works abnormally. | 2360 2361**示例:** 2362 2363```ts 2364let storage = new LocalStorage(); 2365storage.setOrCreate('storageSimpleProp',121); 2366console.log('onWindowStageCreate'); 2367try { 2368 windowClass.loadContent('pages/page2', storage, (err) => { 2369 if (err.code) { 2370 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2371 return; 2372 } 2373 console.info('Succeeded in loading the content.'); 2374 }); 2375} catch (exception) { 2376 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2377} 2378``` 2379 2380### loadContent<sup>9+</sup> 2381 2382loadContent(path: string, storage: LocalStorage): Promise<void> 2383 2384为当前窗口加载与LocalStorage相关联的具体页面内容,使用Promise异步回调。 2385 2386**模型约束:** 此接口仅可在Stage模型下使用。 2387 2388**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2389 2390**参数:** 2391 2392| 参数名 | 类型 | 必填 | 说明 | 2393| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2394| path | string | 是 | 设置加载页面的路径。 | 2395| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 | 2396 2397**返回值:** 2398 2399| 类型 | 说明 | 2400| ------------------- | ------------------------- | 2401| Promise<void> | 无返回结果的Promise对象。 | 2402 2403**错误码:** 2404 2405以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2406 2407| 错误码ID | 错误信息 | 2408| ------- | -------------------------------------------- | 2409| 1300002 | This window state is abnormal. | 2410| 1300003 | This window manager service works abnormally. | 2411 2412**示例:** 2413 2414```ts 2415let storage = new LocalStorage(); 2416storage.setOrCreate('storageSimpleProp',121); 2417console.log('onWindowStageCreate'); 2418try { 2419 let promise = windowClass.loadContent('pages/page2', storage); 2420 promise.then(() => { 2421 console.info('Succeeded in loading the content.'); 2422 }).catch((err) => { 2423 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2424 }); 2425} catch (exception) { 2426 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2427} 2428``` 2429 2430### isWindowShowing<sup>9+</sup> 2431 2432isWindowShowing(): boolean 2433 2434判断当前窗口是否已显示。 2435 2436**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2437 2438**返回值:** 2439 2440| 类型 | 说明 | 2441| ------- | ------------------------------------------------------------------ | 2442| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 | 2443 2444**错误码:** 2445 2446以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2447 2448| 错误码ID | 错误信息 | 2449| ------- | ------------------------------ | 2450| 1300002 | This window state is abnormal. | 2451 2452**示例:** 2453 2454```js 2455try { 2456 let data = windowClass.isWindowShowing(); 2457 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 2458} catch (exception) { 2459 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(exception)); 2460} 2461``` 2462 2463### on('windowSizeChange')<sup>7+</sup> 2464 2465on(type: 'windowSizeChange', callback: Callback<Size>): void 2466 2467开启窗口尺寸变化的监听。 2468 2469**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2470 2471**参数:** 2472 2473| 参数名 | 类型 | 必填 | 说明 | 2474| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 2475| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 2476| callback | Callback<[Size](#size7)> | 是 | 回调函数。返回当前的窗口尺寸。 | 2477 2478**示例:** 2479 2480```js 2481try { 2482 windowClass.on('windowSizeChange', (data) => { 2483 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 2484 }); 2485} catch (exception) { 2486 console.error('Failed to enable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 2487} 2488``` 2489 2490### off('windowSizeChange')<sup>7+</sup> 2491 2492off(type: 'windowSizeChange', callback?: Callback<Size>): void 2493 2494关闭窗口尺寸变化的监听。 2495 2496**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2497 2498**参数:** 2499 2500| 参数名 | 类型 | 必填 | 说明 | 2501| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 2502| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 2503| callback | Callback<[Size](#size7)> | 否 | 回调函数。返回当前的窗口尺寸。 | 2504 2505**示例:** 2506 2507```js 2508try { 2509 windowClass.off('windowSizeChange'); 2510} catch (exception) { 2511 console.error('Failed to disable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 2512} 2513``` 2514 2515### on('avoidAreaChange')<sup>9+</sup> 2516 2517on(type: 'avoidAreaChange', callback: Callback<{AvoidAreaType, AvoidArea}>): void 2518 2519开启系统规避区变化的监听。 2520 2521**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2522 2523**参数:** 2524 2525| 参数名 | 类型 | 必填 | 说明 | 2526| -------- |------------------------------------------------------------------| ---- |--------------------------------------| 2527| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 2528| callback | Callback<{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}> | 是 | 回调函数。返回当前规避区以及规避区类型。| 2529 2530**示例:** 2531 2532```js 2533try { 2534 windowClass.on('avoidAreaChange', (data) => { 2535 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 2536 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 2537 }); 2538} catch (exception) { 2539 console.error('Failed to enable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 2540} 2541``` 2542 2543### off('avoidAreaChange')<sup>9+</sup> 2544 2545off(type: 'avoidAreaChange', callback: Callback<{AvoidAreaType, AvoidArea}>): void 2546 2547关闭系统规避区变化的监听。 2548 2549**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2550 2551**参数:** 2552 2553| 参数名 | 类型 | 必填 | 说明 | 2554| -------- |-----------------------------------------------------------------------------|-----|------------------------------------| 2555| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 2556| callback | Callback<{[AvoidAreaType](#avoidareatype7), [AvoidArea](#avoidarea7)}> | 否 | 回调函数。返回当前规避区以及规避区类型。| 2557 2558**示例:** 2559 2560```js 2561try { 2562 windowClass.off('avoidAreaChange'); 2563} catch (exception) { 2564 console.error('Failed to disable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 2565} 2566``` 2567 2568### on('keyboardHeightChange')<sup>7+</sup> 2569 2570on(type: 'keyboardHeightChange', callback: Callback<number>): void 2571 2572开启键盘高度变化的监听。 2573 2574**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2575 2576**参数:** 2577 2578| 参数名 | 类型 | 必填 | 说明 | 2579| -------- | ------------------- | ---- | ------------------------------------------------------------ | 2580| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 2581| callback | Callback<number> | 是 | 回调函数。返回当前的键盘高度。 | 2582 2583**示例:** 2584 2585```js 2586try { 2587 windowClass.on('keyboardHeightChange', (data) => { 2588 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 2589 }); 2590} catch (exception) { 2591 console.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 2592} 2593``` 2594 2595### off('keyboardHeightChange')<sup>7+</sup> 2596 2597off(type: 'keyboardHeightChange', callback?: Callback<number>): void 2598 2599关闭键盘高度变化的监听。 2600 2601**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2602 2603**参数:** 2604 2605| 参数名 | 类型 | 必填 | 说明 | 2606| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2607| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 2608| callback | Callback<number> | 否 | 回调函数。返回当前的键盘高度。 | 2609 2610**示例:** 2611 2612```js 2613try { 2614 windowClass.off('keyboardHeightChange'); 2615} catch (exception) { 2616 console.error('Failed to disable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 2617} 2618``` 2619 2620### on('touchOutside')<sup>9+</sup> 2621 2622on(type: 'touchOutside', callback: Callback<void>): void 2623 2624开启本窗口区域范围外的点击事件的监听。 2625 2626**系统接口:** 此接口为系统接口。 2627 2628**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2629 2630**参数:** 2631 2632| 参数名 | 类型 | 必填 | 说明 | 2633| -------- | ------------------- | ---- | ------------------------------------------------------------ | 2634| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 2635| callback | Callback<void> | 是 | 回调函数。当点击事件发生在本窗口范围之外的回调。 | 2636 2637**示例:** 2638 2639```js 2640try { 2641 windowClass.on('touchOutside', () => { 2642 console.info('touch outside'); 2643 }); 2644} catch (exception) { 2645 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2646} 2647``` 2648 2649### off('touchOutside')<sup>9+</sup> 2650 2651off(type: 'touchOutside', callback?: Callback<void>): void 2652 2653关闭本窗口区域范围外的点击事件的监听。 2654 2655**系统接口:** 此接口为系统接口。 2656 2657**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2658 2659**参数:** 2660 2661| 参数名 | 类型 | 必填 | 说明 | 2662| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2663| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 2664| callback | Callback<number> | 否 | 回调函数。当点击事件发生在本窗口范围之外的回调。 | 2665 2666**示例:** 2667 2668```js 2669try { 2670 windowClass.off('touchOutside'); 2671} catch (exception) { 2672 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2673} 2674``` 2675 2676### on('screenshot')<sup>9+</sup> 2677 2678on(type: 'screenshot', callback: Callback<void>): void 2679 2680开启截屏事件的监听。 2681 2682**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2683 2684**参数:** 2685 2686| 参数名 | 类型 | 必填 | 说明 | 2687| -------- | ------------------- | ---- | ------------------------------------------------------------ | 2688| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 2689| callback | Callback<void> | 是 | 回调函数。发生截屏事件时的回调。 | 2690 2691**示例:** 2692 2693```js 2694try { 2695 windowClass.on('screenshot', () => { 2696 console.info('screenshot happened'); 2697 }); 2698} catch (exception) { 2699 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2700} 2701``` 2702 2703### off('screenshot')<sup>9+</sup> 2704 2705off(type: 'screenshot', callback?: Callback<void>): void 2706 2707关闭截屏事件的监听。 2708 2709**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2710 2711**参数:** 2712 2713| 参数名 | 类型 | 必填 | 说明 | 2714| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2715| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 2716| callback | Callback<void> | 否 | 回调函数。发生截屏事件时的回调。 | 2717 2718**示例:** 2719 2720```js 2721let callback = () => { 2722 console.info('screenshot happened'); 2723}; 2724try { 2725 windowClass.on('screenshot', callback); 2726} catch (exception) { 2727 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 2728} 2729try { 2730 windowClass.off('screenshot', callback); 2731 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 2732 windowClass.off('screenshot'); 2733} catch (exception) { 2734 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 2735} 2736``` 2737 2738### bindDialogTarget<sup>9+</sup> 2739 2740bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 2741 2742绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 2743 2744**系统接口:** 此接口为系统接口。 2745 2746**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2747 2748**参数:** 2749 2750| 参数名 | 类型 | 必填 | 说明 | 2751| ----------- | ------------------------- | ---- | -------------------- | 2752| token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | 2753| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 2754| callback | AsyncCallback<void> | 是 | 回调函数。 | 2755 2756**错误码:** 2757 2758以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2759 2760| 错误码ID | 错误信息 | 2761| ------- | -------------------------------------------- | 2762| 1300002 | This window state is abnormal. | 2763| 1300003 | This window manager service works abnormally. | 2764 2765**示例:** 2766 2767```js 2768import rpc from '@ohos.rpc'; 2769 2770class MyDeathRecipient { 2771 onRemoteDied() { 2772 console.log('server died'); 2773 } 2774} 2775class TestRemoteObject extends rpc.RemoteObject { 2776 constructor(descriptor) { 2777 super(descriptor); 2778 } 2779 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 2780 return true; 2781 } 2782 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 2783 return true; 2784 } 2785 isObjectDead(): boolean { 2786 return false; 2787 } 2788} 2789 2790let token = new TestRemoteObject('testObject'); 2791try { 2792 windowClass.bindDialogTarget(token, () => { 2793 console.info('Dialog Window Need Destroy.'); 2794 }, (err) => { 2795 if (err.code) { 2796 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 2797 return; 2798 } 2799 console.info('Succeeded in binding dialog target.'); 2800 }); 2801} catch (exception) { 2802 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception)); 2803} 2804``` 2805 2806### bindDialogTarget<sup>9+</sup> 2807 2808bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void> 2809 2810绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 2811 2812**系统接口:** 此接口为系统接口。 2813 2814**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2815 2816**参数:** 2817 2818| 参数名 | 类型 | 必填 | 说明 | 2819| ----------- | ------------------------- | ---- | -------------------- | 2820| token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | 2821| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 2822 2823**返回值:** 2824 2825| 类型 | 说明 | 2826| ------------------- | ------------------------- | 2827| Promise<void> | 无返回结果的Promise对象。 | 2828 2829**错误码:** 2830 2831以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2832 2833| 错误码ID | 错误信息 | 2834| ------- | -------------------------------------------- | 2835| 1300002 | This window state is abnormal. | 2836| 1300003 | This window manager service works abnormally. | 2837 2838**示例:** 2839 2840```js 2841import rpc from '@ohos.rpc'; 2842 2843class MyDeathRecipient { 2844 onRemoteDied() { 2845 console.log('server died'); 2846 } 2847} 2848class TestRemoteObject extends rpc.RemoteObject { 2849 constructor(descriptor) { 2850 super(descriptor); 2851 } 2852 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 2853 return true; 2854 } 2855 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 2856 return true; 2857 } 2858 isObjectDead(): boolean { 2859 return false; 2860 } 2861} 2862 2863let token = new TestRemoteObject('testObject'); 2864try { 2865 let promise = windowClass.bindDialogTarget(token, () => { 2866 console.info('Dialog Window Need Destroy.'); 2867 }); 2868 promise.then(()=> { 2869 console.info('Succeeded in binding dialog target.'); 2870 }).catch((err)=>{ 2871 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 2872 }); 2873} catch (exception) { 2874 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception)); 2875} 2876``` 2877 2878### isWindowSupportWideGamut<sup>9+</sup> 2879 2880isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 2881 2882判断当前窗口是否支持广色域模式,使用callback异步回调。 2883 2884**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2885 2886**参数:** 2887 2888| 参数名 | 类型 | 必填 | 说明 | 2889| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 2890| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 2891 2892**错误码:** 2893 2894以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2895 2896| 错误码ID | 错误信息 | 2897| ------- | ------------------------------ | 2898| 1300002 | This window state is abnormal. | 2899 2900**示例:** 2901 2902```js 2903windowClass.isWindowSupportWideGamut((err, data) => { 2904 if (err.code) { 2905 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 2906 return; 2907 } 2908 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 2909}); 2910``` 2911 2912### isWindowSupportWideGamut<sup>9+</sup> 2913 2914isWindowSupportWideGamut(): Promise<boolean> 2915 2916判断当前窗口是否支持广色域模式,使用Promise异步回调。 2917 2918**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2919 2920**返回值:** 2921 2922| 类型 | 说明 | 2923| ---------------------- | ------------------------------------------------------------------------------------ | 2924| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 2925 2926**错误码:** 2927 2928以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2929 2930| 错误码ID | 错误信息 | 2931| ------- | ------------------------------ | 2932| 1300002 | This window state is abnormal. | 2933 2934**示例:** 2935 2936```js 2937let promise = windowClass.isWindowSupportWideGamut(); 2938promise.then((data)=> { 2939 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 2940}).catch((err)=>{ 2941 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 2942}); 2943``` 2944 2945### setWindowColorSpace<sup>9+</sup> 2946 2947setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 2948 2949设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 2950 2951**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2952 2953**参数:** 2954 2955| 参数名 | 类型 | 必填 | 说明 | 2956| ---------- | ------------------------- | -- | ----------- | 2957| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 2958| callback | AsyncCallback<void> | 是 | 回调函数。 | 2959 2960**错误码:** 2961 2962以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2963 2964| 错误码ID | 错误信息 | 2965| ------- | ------------------------------ | 2966| 1300002 | This window state is abnormal. | 2967 2968**示例:** 2969 2970```js 2971try { 2972 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err) => { 2973 if (err.code) { 2974 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 2975 return; 2976 } 2977 console.info('Succeeded in setting window colorspace.'); 2978 }); 2979} catch (exception) { 2980 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 2981} 2982``` 2983 2984### setWindowColorSpace<sup>9+</sup> 2985 2986setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 2987 2988设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 2989 2990**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2991 2992**参数:** 2993 2994| 参数名 | 类型 | 必填 | 说明 | 2995| ---------- | ------------------------- | -- | ------------- | 2996| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 2997 2998**返回值:** 2999 3000| 类型 | 说明 | 3001| ------------------- | ------------------------ | 3002| Promise<void> | 无返回结果的Promise对象。 | 3003 3004**错误码:** 3005 3006以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3007 3008| 错误码ID | 错误信息 | 3009| ------- | ------------------------------ | 3010| 1300002 | This window state is abnormal. | 3011 3012**示例:** 3013 3014```js 3015try { 3016 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 3017 promise.then(()=> { 3018 console.info('Succeeded in setting window colorspace.'); 3019 }).catch((err)=>{ 3020 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 3021 }); 3022} catch (exception) { 3023 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3024} 3025``` 3026 3027### getWindowColorSpace<sup>9+</sup> 3028 3029getWindowColorSpace(): ColorSpace 3030 3031获取当前窗口色域模式。 3032 3033**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3034 3035**返回值:** 3036 3037| 类型 | 说明 | 3038| ------------------------- | ------------- | 3039| [ColorSpace](#colorspace8) | 当前色域模式。 | 3040 3041**错误码:** 3042 3043以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3044 3045| 错误码ID | 错误信息 | 3046| ------- | ------------------------------ | 3047| 1300002 | This window state is abnormal. | 3048 3049**示例:** 3050 3051```js 3052let colorSpace = windowClass.getWindowColorSpace(); 3053``` 3054 3055### setWindowBackgroundColor<sup>9+</sup> 3056 3057setWindowBackgroundColor(color: string): void 3058 3059设置窗口的背景色。Stage模型下,该接口需要在[loadContent](#loadcontent9)之后使用。 3060 3061**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3062 3063**参数:** 3064 3065| 参数名 | 类型 | 必填 | 说明 | 3066| ----- | ------ | -- | ----------------------------------------------------------------------- | 3067| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 3068 3069**错误码:** 3070 3071以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3072 3073| 错误码ID | 错误信息 | 3074| ------- | ------------------------------ | 3075| 1300002 | This window state is abnormal. | 3076 3077**示例:** 3078 3079```js 3080let color = '#00ff33'; 3081try { 3082 windowClass.setWindowBackgroundColor(color); 3083} catch (exception) { 3084 console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception)); 3085} 3086``` 3087 3088### setWindowBrightness<sup>9+</sup> 3089 3090setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 3091 3092设置屏幕亮度值,使用callback异步回调。 3093 3094**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3095 3096**参数:** 3097 3098| 参数名 | 类型 | 必填 | 说明 | 3099| ---------- | ------------------------- | -- | --------------------------------- | 3100| brightness | number | 是 | 屏幕亮度值,值为0-1之间。1表示最亮。 | 3101| callback | AsyncCallback<void> | 是 | 回调函数。 | 3102 3103**错误码:** 3104 3105以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3106 3107| 错误码ID | 错误信息 | 3108| ------- | -------------------------------------------- | 3109| 1300002 | This window state is abnormal. | 3110| 1300003 | This window manager service works abnormally. | 3111 3112**示例:** 3113 3114```js 3115let brightness = 1; 3116try { 3117 windowClass.setWindowBrightness(brightness, (err) => { 3118 if (err.code) { 3119 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 3120 return; 3121 } 3122 console.info('Succeeded in setting the brightness.'); 3123 }); 3124} catch (exception) { 3125 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 3126} 3127``` 3128 3129### setWindowBrightness<sup>9+</sup> 3130 3131setWindowBrightness(brightness: number): Promise<void> 3132 3133设置屏幕亮度值,使用Promise异步回调。 3134 3135**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3136 3137**参数:** 3138 3139| 参数名 | 类型 | 必填 | 说明 | 3140| ---------- | ------ | -- | --------------------------------- | 3141| brightness | number | 是 | 屏幕亮度值,值为0-1之间。1表示最亮。 | 3142 3143**返回值:** 3144 3145| 类型 | 说明 | 3146| ------------------- | ------------------------ | 3147| Promise<void> | 无返回结果的Promise对象。 | 3148 3149**错误码:** 3150 3151以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3152 3153| 错误码ID | 错误信息 | 3154| ------- | -------------------------------------------- | 3155| 1300002 | This window state is abnormal. | 3156| 1300003 | This window manager service works abnormally. | 3157 3158**示例:** 3159 3160```js 3161let brightness = 1; 3162try { 3163 let promise = windowClass.setWindowBrightness(brightness); 3164 promise.then(()=> { 3165 console.info('Succeeded in setting the brightness.'); 3166 }).catch((err)=>{ 3167 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 3168 }); 3169} catch (exception) { 3170 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 3171} 3172``` 3173 3174### setWindowFocusable<sup>9+</sup> 3175 3176setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 3177 3178设置点击时是否支持切换焦点窗口,使用callback异步回调。 3179 3180**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3181 3182**参数:** 3183 3184| 参数名 | 类型 | 必填 | 说明 | 3185| ----------- | ------------------------- | -- | ------------------------------------------------------- | 3186| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 3187| callback | AsyncCallback<void> | 是 | 回调函数。 | 3188 3189**错误码:** 3190 3191以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3192 3193| 错误码ID | 错误信息 | 3194| ------- | -------------------------------------------- | 3195| 1300002 | This window state is abnormal. | 3196| 1300003 | This window manager service works abnormally. | 3197 3198**示例:** 3199 3200```js 3201let isFocusable = true; 3202try { 3203 windowClass.setWindowFocusable(isFocusable, (err) => { 3204 if (err.code) { 3205 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 3206 return; 3207 } 3208 console.info('Succeeded in setting the window to be focusable.'); 3209 }); 3210} catch (exception) { 3211 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 3212} 3213``` 3214 3215### setWindowFocusable<sup>9+</sup> 3216 3217setWindowFocusable(isFocusable: boolean): Promise<void> 3218 3219设置点击时是否支持切换焦点窗口,使用Promise异步回调。 3220 3221**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3222 3223**参数:** 3224 3225| 参数名 | 类型 | 必填 | 说明 | 3226| ----------- | ------- | -- | -------------------------------------------------------- | 3227| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 3228 3229**返回值:** 3230 3231| 类型 | 说明 | 3232| ------------------- | ------------------------ | 3233| Promise<void> | 无返回结果的Promise对象。 | 3234 3235**错误码:** 3236 3237以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3238 3239| 错误码ID | 错误信息 | 3240| ------- | -------------------------------------------- | 3241| 1300002 | This window state is abnormal. | 3242| 1300003 | This window manager service works abnormally. | 3243 3244**示例:** 3245 3246```js 3247let isFocusable = true; 3248try { 3249 let promise = windowClass.setWindowFocusable(isFocusable); 3250 promise.then(()=> { 3251 console.info('Succeeded in setting the window to be focusable.'); 3252 }).catch((err)=>{ 3253 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 3254 }); 3255} catch (exception) { 3256 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 3257} 3258``` 3259 3260### setWindowKeepScreenOn<sup>9+</sup> 3261 3262setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 3263 3264设置屏幕是否为常亮状态,使用callback异步回调。 3265 3266**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3267 3268**参数:** 3269 3270| 参数名 | 类型 | 必填 | 说明 | 3271| -------------- | ------------------------- | -- | ---------------------------------------------------- | 3272| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 3273| callback | AsyncCallback<void> | 是 | 回调函数。 | 3274 3275**错误码:** 3276 3277以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3278 3279| 错误码ID | 错误信息 | 3280| ------- | -------------------------------------------- | 3281| 1300002 | This window state is abnormal. | 3282| 1300003 | This window manager service works abnormally. | 3283 3284**示例:** 3285 3286```js 3287let isKeepScreenOn = true; 3288try { 3289 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err) => { 3290 if (err.code) { 3291 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 3292 return; 3293 } 3294 console.info('Succeeded in setting the screen to be always on.'); 3295 }); 3296} catch (exception) { 3297 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 3298} 3299``` 3300 3301### setWindowKeepScreenOn<sup>9+</sup> 3302 3303setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 3304 3305设置屏幕是否为常亮状态,使用Promise异步回调。 3306 3307**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3308 3309**参数:** 3310 3311| 参数名 | 类型 | 必填 | 说明 | 3312| -------------- | ------- | -- | --------------------------------------------------- | 3313| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 3314 3315**返回值:** 3316 3317| 类型 | 说明 | 3318| ------------------- | ------------------------ | 3319| Promise<void> | 无返回结果的Promise对象。 | 3320 3321**错误码:** 3322 3323以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3324 3325| 错误码ID | 错误信息 | 3326| ------- | -------------------------------------------- | 3327| 1300002 | This window state is abnormal. | 3328| 1300003 | This window manager service works abnormally. | 3329 3330**示例:** 3331 3332```js 3333let isKeepScreenOn = true; 3334try { 3335 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 3336 promise.then(() => { 3337 console.info('Succeeded in setting the screen to be always on.'); 3338 }).catch((err)=>{ 3339 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 3340 }); 3341} catch (exception) { 3342 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 3343} 3344``` 3345 3346### setWakeUpScreen()<sup>9+</sup> 3347 3348setWakeUpScreen(wakeUp: boolean): void 3349 3350窗口唤醒屏幕。 3351 3352**系统接口:** 此接口为系统接口。 3353 3354**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3355 3356**参数:** 3357 3358| 参数名 | 类型 | 必填 | 说明 | 3359| ---------------- | ------- | ---- | ---------------------------- | 3360| wakeUp | boolean | 是 | 是否设置唤醒屏幕。true表示唤醒;false表示不唤醒。 | 3361 3362**错误码:** 3363 3364以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3365 3366| 错误码ID | 错误信息 | 3367| ------- | -------------------------------------------- | 3368| 1300002 | This window state is abnormal. | 3369| 1300003 | This window manager service works abnormally. | 3370 3371**示例:** 3372 3373```js 3374let wakeUp = true; 3375try { 3376 windowClass.setWakeUpScreen(wakeUp); 3377} catch (exception) { 3378 console.error('Failed to wake up the screen. Cause: ' + JSON.stringify(exception)); 3379} 3380``` 3381 3382### setWindowPrivacyMode<sup>9+</sup> 3383 3384setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 3385 3386设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。 3387 3388**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3389 3390**需要权限:** ohos.permission.PRIVACY_WINDOW 3391 3392**参数:** 3393 3394| 参数名 | 类型 | 必填 | 说明 | 3395| ------------- | ------------------------- | -- | ------------------------------------------------------ | 3396| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 3397| callback | AsyncCallback<void> | 是 | 回调函数。 | 3398 3399**错误码:** 3400 3401以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3402 3403| 错误码ID | 错误信息 | 3404| ------- | ------------------------------ | 3405| 1300002 | This window state is abnormal. | 3406 3407**示例:** 3408 3409```js 3410let isPrivacyMode = true; 3411try { 3412 windowClass.setWindowPrivacyMode(isPrivacyMode, (err) => { 3413 if (err.code) { 3414 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 3415 return; 3416 } 3417 console.info('Succeeded in setting the window to privacy mode.'); 3418 }); 3419} catch (exception) { 3420 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 3421} 3422``` 3423 3424### setWindowPrivacyMode<sup>9+</sup> 3425 3426setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 3427 3428设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。 3429 3430**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3431 3432**需要权限:** ohos.permission.PRIVACY_WINDOW 3433 3434**参数:** 3435 3436| 参数名 | 类型 | 必填 | 说明 | 3437| ------------- | ------- | -- | ----------------------------------------------------- | 3438| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 3439 3440**返回值:** 3441 3442| 类型 | 说明 | 3443| ------------------- | ------------------------ | 3444| Promise<void> | 无返回结果的Promise对象。 | 3445 3446**错误码:** 3447 3448以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3449 3450| 错误码ID | 错误信息 | 3451| ------- | ------------------------------ | 3452| 1300002 | This window state is abnormal. | 3453 3454**示例:** 3455 3456```js 3457let isPrivacyMode = true; 3458try { 3459 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 3460 promise.then(()=> { 3461 console.info('Succeeded in setting the window to privacy mode.'); 3462 }).catch((err)=>{ 3463 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 3464 }); 3465} catch (exception) { 3466 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 3467} 3468``` 3469 3470### setSnapshotSkip<sup>9+</sup> 3471setSnapshotSkip(isSkip: boolean): void 3472 3473截屏录屏是否忽略当前窗口。 3474 3475**系统接口:** 此接口为系统接口。 3476 3477**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3478 3479**参数:** 3480 3481| 参数名 | 类型 | 必填 | 说明 | 3482| ------------- | ------- | ---- | -------------------- | 3483| isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。<br>true表示忽略当前窗口,false表示不忽略当前窗口。</br> | 3484 3485**错误码:** 3486 3487以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3488 3489| 错误码ID | 错误信息 | 3490| ------- | ------------------------------ | 3491| 1300002 | This window state is abnormal. | 3492 3493```js 3494let isSkip = true; 3495try { 3496 windowClass.setSnapshotSkip(isSkip); 3497} catch (exception) { 3498 console.error('Failed to Skip. Cause: ' + JSON.stringify(exception)); 3499}; 3500``` 3501 3502### setWindowTouchable<sup>9+</sup> 3503 3504setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 3505 3506设置窗口是否为可触状态,使用callback异步回调。 3507 3508**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3509 3510**参数:** 3511 3512| 参数名 | 类型 | 必填 | 说明 | 3513| ----------- | ------------------------- | -- | ----------------------------------------------- | 3514| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 3515| callback | AsyncCallback<void> | 是 | 回调函数。 | 3516 3517**错误码:** 3518 3519以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3520 3521| 错误码ID | 错误信息 | 3522| ------- | -------------------------------------------- | 3523| 1300002 | This window state is abnormal. | 3524| 1300003 | This window manager service works abnormally. | 3525 3526**示例:** 3527 3528```js 3529let isTouchable = true; 3530try { 3531 windowClass.setWindowTouchable(isTouchable, (err) => { 3532 if (err.code) { 3533 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 3534 return; 3535 } 3536 console.info('Succeeded in setting the window to be touchable.'); 3537 }); 3538} catch (exception) { 3539 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 3540} 3541``` 3542 3543### setWindowTouchable<sup>9+</sup> 3544 3545setWindowTouchable(isTouchable: boolean): Promise<void> 3546 3547设置窗口是否为可触状态,使用Promise异步回调。 3548 3549**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3550 3551**参数:** 3552 3553| 参数名 | 类型 | 必填 | 说明 | 3554| ----------- | ------- | -- | ----------------------------------------------- | 3555| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 3556 3557**返回值:** 3558 3559| 类型 | 说明 | 3560| ------------------- | ------------------------- | 3561| Promise<void> | 无返回结果的Promise对象。 | 3562 3563**错误码:** 3564 3565以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3566 3567| 错误码ID | 错误信息 | 3568| ------- | -------------------------------------------- | 3569| 1300002 | This window state is abnormal. | 3570| 1300003 | This window manager service works abnormally. | 3571 3572**示例:** 3573 3574```js 3575let isTouchable = true; 3576try { 3577 let promise = windowClass.setWindowTouchable(isTouchable); 3578 promise.then(()=> { 3579 console.info('Succeeded in setting the window to be touchable.'); 3580 }).catch((err)=>{ 3581 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 3582 }); 3583} catch (exception) { 3584 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 3585} 3586``` 3587 3588### setForbidSplitMove<sup>9+</sup> 3589 3590setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void 3591 3592设置窗口在分屏模式下是否被禁止移动,使用callback异步回调。 3593 3594**系统接口:** 此接口为系统接口。 3595 3596**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3597 3598**参数:** 3599 3600| 参数名 | 类型 | 必填 | 说明 | 3601| ----------- | ------------------------- | ---- | -------------------- | 3602| isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | 3603| callback | AsyncCallback<void> | 是 | 回调函数。 | 3604 3605**错误码:** 3606 3607以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3608 3609| 错误码ID | 错误信息 | 3610| ------- | -------------------------------------------- | 3611| 1300002 | This window state is abnormal. | 3612| 1300003 | This window manager service works abnormally. | 3613 3614**示例:** 3615 3616```js 3617let isForbidSplitMove = true; 3618try { 3619 windowClass.setForbidSplitMove(isForbidSplitMove, (err) => { 3620 if (err.code) { 3621 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(err)); 3622 return; 3623 } 3624 console.info('Succeeded in forbidding window moving in split screen mode.'); 3625 }); 3626} catch (exception) { 3627 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception)); 3628} 3629``` 3630 3631### setForbidSplitMove<sup>9+</sup> 3632 3633setForbidSplitMove(isForbidSplitMove: boolean): Promise<void> 3634 3635设置窗口在分屏模式下是否被禁止移动,使用Promise异步回调。 3636 3637**系统接口:** 此接口为系统接口。 3638 3639**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3640 3641**参数:** 3642 3643| 参数名 | 类型 | 必填 | 说明 | 3644| ----------- | ------- | ---- | -------------------- | 3645| isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | 3646 3647**返回值:** 3648 3649| 类型 | 说明 | 3650| ------------------- | ------------------------- | 3651| Promise<void> | 无返回结果的Promise对象。 | 3652 3653**错误码:** 3654 3655以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3656 3657| 错误码ID | 错误信息 | 3658| ------- | -------------------------------------------- | 3659| 1300002 | This window state is abnormal. | 3660| 1300003 | This window manager service works abnormally. | 3661 3662**示例:** 3663 3664```js 3665let isForbidSplitMove = true; 3666try { 3667 let promise = windowClass.setForbidSplitMove(isForbidSplitMove); 3668 promise.then(()=> { 3669 console.info('Succeeded in forbidding window moving in split screen mode.'); 3670 }).catch((err)=>{ 3671 console.error('Failed to forbid window moving in split screen mode. Cause: ' + JSON.stringify(err)); 3672 }); 3673} catch (exception) { 3674 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception)); 3675} 3676``` 3677 3678### snapshot<sup>9+</sup> 3679 3680snapshot(callback: AsyncCallback<image.PixelMap>): void 3681 3682获取窗口截图,使用callback异步回调。 3683 3684**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3685 3686**参数:** 3687 3688| 参数名 | 类型 | 必填 | 说明 | 3689| ----------- | ------------------------- | ---- | -------------------- | 3690| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | 是 | 回调函数。 | 3691 3692**错误码:** 3693 3694以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3695 3696| 错误码ID | 错误信息 | 3697| ------- | ------------------------------ | 3698| 1300002 | This window state is abnormal. | 3699 3700**示例:** 3701 3702```js 3703windowClass.snapshot((err, pixelMap) => { 3704 if (err.code) { 3705 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 3706 return; 3707 } 3708 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 3709 pixelMap.release(); // PixelMap使用完后及时释放内存 3710}); 3711``` 3712 3713### snapshot<sup>9+</sup> 3714 3715snapshot(): Promise<image.PixelMap> 3716 3717获取窗口截图,使用Promise异步回调。 3718 3719**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3720 3721**返回值:** 3722 3723| 类型 | 说明 | 3724| ------------------- | ------------------------- | 3725| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | 3726 3727**错误码:** 3728 3729以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3730 3731| 错误码ID | 错误信息 | 3732| ------- | ------------------------------ | 3733| 1300002 | This window state is abnormal. | 3734 3735**示例:** 3736 3737```js 3738let promise = windowClass.snapshot(); 3739promise.then((pixelMap)=> { 3740 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 3741 pixelMap.release(); // PixelMap使用完后及时释放内存 3742}).catch((err)=>{ 3743 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 3744}); 3745``` 3746 3747### opacity<sup>9+</sup> 3748 3749opacity(opacity: number): void 3750 3751设置窗口透明度。 3752 3753**系统接口:** 此接口为系统接口。 3754 3755**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3756 3757**参数:** 3758 3759| 参数名 | 类型 | 必填 | 说明 | 3760| ------- | ------ | ---- | --------------------- | 3761| opacity | number | 是 | 透明度,范围0.0~1.0。 | 3762 3763**错误码:** 3764 3765以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3766 3767| 错误码ID | 错误信息 | 3768| ------- | ------------------------------ | 3769| 1300002 | This window state is abnormal. | 3770| 1300004 | Unauthorized operation. | 3771 3772**示例:** 3773 3774```js 3775try { 3776 windowClass.opacity(0.5); 3777} catch (exception) { 3778 console.error('Failed to opacity. Cause: ' + JSON.stringify(exception)); 3779} 3780``` 3781 3782### scale<sup>9+</sup> 3783 3784scale(scaleOptions: ScaleOptions): void 3785 3786设置窗口缩放参数。 3787 3788**系统接口:** 此接口为系统接口。 3789 3790**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3791 3792**参数:** 3793 3794| 参数名 | 类型 | 必填 | 说明 | 3795| ------------ | ------------------------------ | ---- | ---------- | 3796| scaleOptions | [ScaleOptions](#scaleoptions9) | 是 | 缩放参数。 | 3797 3798**错误码:** 3799 3800以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3801 3802| 错误码ID | 错误信息 | 3803| ------- | ------------------------------ | 3804| 1300002 | This window state is abnormal. | 3805| 1300004 | Unauthorized operation. | 3806 3807**示例:** 3808 3809```js 3810let obj : window.ScaleOptions = { 3811 x : 2.0, 3812 y : 1.0, 3813 pivotX : 0.5, 3814 pivotY : 0.5 3815}; 3816try { 3817 windowClass.scale(obj); 3818} catch (exception) { 3819 console.error('Failed to scale. Cause: ' + JSON.stringify(exception)); 3820} 3821``` 3822 3823### rotate<sup>9+</sup> 3824 3825rotate(rotateOptions: RotateOptions): void 3826 3827设置窗口旋转参数。 3828 3829**系统接口:** 此接口为系统接口。 3830 3831**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3832 3833**参数:** 3834 3835| 参数名 | 类型 | 必填 | 说明 | 3836| ------------- | -------------------------------- | ---- | ---------- | 3837| rotateOptions | [RotateOptions](#rotateoptions9) | 是 | 旋转参数。 | 3838 3839**错误码:** 3840 3841以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3842 3843| 错误码ID | 错误信息 | 3844| ------- | ------------------------------ | 3845| 1300002 | This window state is abnormal. | 3846| 1300004 | Unauthorized operation. | 3847 3848**示例:** 3849 3850```js 3851let obj : window.RotateOptions = { 3852 x : 1.0, 3853 y : 1.0, 3854 z : 45.0, 3855 pivotX : 0.5, 3856 pivotY : 0.5 3857}; 3858try { 3859 windowClass.rotate(obj); 3860} catch (exception) { 3861 console.error('Failed to rotate. Cause: ' + JSON.stringify(exception)); 3862} 3863``` 3864 3865### translate<sup>9+</sup> 3866 3867translate(translateOptions: TranslateOptions): void 3868 3869设置窗口平移参数。 3870 3871**系统接口:** 此接口为系统接口。 3872 3873**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3874 3875**参数:** 3876 3877| 参数名 | 类型 | 必填 | 说明 | 3878| ---------------- | -------------------------------------- | ---- | ---------- | 3879| translateOptions | [TranslateOptions](#translateoptions9) | 是 | 平移参数。 | 3880 3881**错误码:** 3882 3883以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3884 3885| 错误码ID | 错误信息 | 3886| ------- | ------------------------------ | 3887| 1300002 | This window state is abnormal. | 3888| 1300004 | Unauthorized operation. | 3889 3890**示例:** 3891 3892```js 3893let obj : window.TranslateOptions = { 3894 x : 100.0, 3895 y : 0.0, 3896 z : 0.0 3897}; 3898try { 3899 windowClass.translate(obj); 3900} catch (exception) { 3901 console.error('Failed to translate. Cause: ' + JSON.stringify(exception)); 3902} 3903``` 3904 3905### getTransitionController<sup>9+</sup> 3906 3907 getTransitionController(): TransitionController 3908 3909获取窗口属性转换控制器。 3910 3911**系统接口:** 此接口为系统接口。 3912 3913**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3914 3915**返回值:** 3916 3917| 类型 | 说明 | 3918| ---------------------------------------------- | ---------------- | 3919| [TransitionController](#transitioncontroller9) | 属性转换控制器。 | 3920 3921**错误码:** 3922 3923以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3924 3925| 错误码ID | 错误信息 | 3926| ------- | ------------------------------ | 3927| 1300002 | This window state is abnormal. | 3928| 1300004 | Unauthorized operation. | 3929 3930**示例:** 3931 3932```js 3933let controller = windowClass.getTransitionController(); // 获取属性转换控制器 3934controller.animationForHidden = (context : window.TransitionContext) => { 3935 let toWindow = context.toWindow; 3936 animateTo({ 3937 duration: 1000, // 动画时长 3938 tempo: 0.5, // 播放速率 3939 curve: Curve.EaseInOut, // 动画曲线 3940 delay: 0, // 动画延迟 3941 iterations: 1, // 播放次数 3942 playMode: PlayMode.Normal, // 动画模式 3943 onFinish: ()=> { 3944 context.completeTransition(true) 3945 } 3946 }, () => { 3947 let obj : window.TranslateOptions = { 3948 x : 100.0, 3949 y : 0.0, 3950 z : 0.0 3951 }; 3952 toWindow.translate(obj); // 设置动画过程中的属性转换 3953 console.info('toWindow translate end'); 3954 } 3955 ); 3956 console.info('complete transition end'); 3957}; 3958windowClass.hideWithAnimation((err, data) => { 3959 if (err.code) { 3960 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 3961 return; 3962 } 3963 console.info('Succeeded in showing the window with animation. Data: ' + JSON.stringify(data)); 3964}); 3965``` 3966 3967### setBlur<sup>9+</sup> 3968 3969setBlur(radius: number): void 3970 3971设置窗口模糊。 3972 3973**系统接口:** 此接口为系统接口。 3974 3975**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3976 3977**参数:** 3978 3979| 参数名 | 类型 | 必填 | 说明 | 3980| ------ | ------ | ---- | ------------------------------------------------------------ | 3981| radius | number | 是 | 表示窗口模糊的半径值,取值范围为大于等于0,0表示关闭窗口模糊。 | 3982 3983**错误码:** 3984 3985以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3986 3987| 错误码ID | 错误信息 | 3988| ------- | ------------------------------ | 3989| 1300002 | This window state is abnormal. | 3990| 1300004 | Unauthorized operation. | 3991 3992**示例:** 3993 3994```js 3995try { 3996 windowClass.setBlur(4.0); 3997} catch (exception) { 3998 console.error('Failed to set blur. Cause: ' + JSON.stringify(exception)); 3999} 4000``` 4001 4002### setBackdropBlur<sup>9+</sup> 4003 4004setBackdropBlur(radius: number): void 4005 4006设置窗口背景模糊。 4007 4008**系统接口:** 此接口为系统接口。 4009 4010**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4011 4012**参数:** 4013 4014| 参数名 | 类型 | 必填 | 说明 | 4015| ------ | ------ | ---- | ------------------------------------------------------------ | 4016| radius | number | 是 | 表示窗口背景模糊的半径值,取值范围为大于等于0,0表示关闭窗口背景模糊。 | 4017 4018**错误码:** 4019 4020以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4021 4022| 错误码ID | 错误信息 | 4023| ------- | ------------------------------ | 4024| 1300002 | This window state is abnormal. | 4025| 1300004 | Unauthorized operation. | 4026 4027**示例:** 4028 4029```js 4030try { 4031 windowClass.setBackdropBlur(4.0); 4032} catch (exception) { 4033 console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception)); 4034} 4035``` 4036 4037### setBackdropBlurStyle<sup>9+</sup> 4038 4039setBackdropBlurStyle(blurStyle: BlurStyle): void 4040 4041设置窗口背景模糊类型。 4042 4043**系统接口:** 此接口为系统接口。 4044 4045**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4046 4047**参数:** 4048 4049| 参数名 | 类型 | 必填 | 说明 | 4050| --------- | --------- | ---- | ---------------------- | 4051| blurStyle | [BlurStyle](#blurstyle9) | 是 | 表示窗口背景模糊类型。 | 4052 4053**错误码:** 4054 4055以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4056 4057| 错误码ID | 错误信息 | 4058| ------- | ------------------------------ | 4059| 1300002 | This window state is abnormal. | 4060| 1300004 | Unauthorized operation. | 4061 4062**示例:** 4063 4064```js 4065try { 4066 windowClass.setBackdropBlurStyle(window.BlurStyle.THIN); 4067} catch (exception) { 4068 console.error('Failed to set backdrop blur style. Cause: ' + JSON.stringify(exception)); 4069} 4070``` 4071 4072### setShadow<sup>9+</sup> 4073 4074setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void 4075 4076设置窗口边缘阴影。 4077 4078**系统接口:** 此接口为系统接口。 4079 4080**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4081 4082**参数:** 4083 4084| 参数名 | 类型 | 必填 | 说明 | 4085| ------- | ------ | ---- | ------------------------------------------------------------ | 4086| radius | number | 是 | 表示窗口边缘阴影的模糊半径,取值范围为大于等于0,0表示关闭窗口边缘阴影。 | 4087| color | string | 否 | 表示窗口边缘阴影的颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 4088| offsetX | number | 否 | 表示窗口边缘阴影的X轴的偏移量,单位为px。 | 4089| offsetY | number | 否 | 表示窗口边缘阴影的Y轴的偏移量,单位为px。 | 4090 4091**错误码:** 4092 4093以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4094 4095| 错误码ID | 错误信息 | 4096| ------- | ------------------------------ | 4097| 1300002 | This window state is abnormal. | 4098| 1300004 | Unauthorized operation. | 4099 4100**示例:** 4101 4102```js 4103try { 4104 windowClass.setShadow(4.0, '#FF00FF00', 2, 3); 4105} catch (exception) { 4106 console.error('Failed to set shadow. Cause: ' + JSON.stringify(exception)); 4107} 4108``` 4109 4110### setCornerRadius<sup>9+</sup> 4111 4112setCornerRadius(cornerRadius: number): void 4113 4114设置窗口圆角半径。 4115 4116**系统接口:** 此接口为系统接口。 4117 4118**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4119 4120**参数:** 4121 4122| 参数名 | 类型 | 必填 | 说明 | 4123| ----------- | ------- | ---- | -------------------- | 4124| radius | number | 是 | 表示窗口圆角的半径值,取值范围为大于等于0,0表示没有窗口圆角。 | 4125 4126**错误码:** 4127 4128以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4129 4130| 错误码ID | 错误信息 | 4131| ------- | ------------------------------ | 4132| 1300002 | This window state is abnormal. | 4133| 1300004 | Unauthorized operation. | 4134 4135**示例:** 4136 4137```js 4138try { 4139 windowClass.setCornerRadius(4.0); 4140} catch (exception) { 4141 console.error('Failed to set corner radius. Cause: ' + JSON.stringify(exception)); 4142} 4143``` 4144 4145### show<sup>(deprecated)</sup> 4146 4147show(callback: AsyncCallback<void>): void 4148 4149显示当前窗口,使用callback异步回调。 4150 4151> **说明:** 4152> 4153> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。 4154 4155**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4156 4157**参数:** 4158 4159| 参数名 | 类型 | 必填 | 说明 | 4160| -------- | ------------------------- | ---- | ---------- | 4161| callback | AsyncCallback<void> | 是 | 回调函数。 | 4162 4163**示例:** 4164 4165```js 4166windowClass.show((err) => { 4167 if (err.code) { 4168 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 4169 return; 4170 } 4171 console.info('Succeeded in showing the window.'); 4172}); 4173``` 4174 4175### show<sup>(deprecated)</sup> 4176 4177show(): Promise<void> 4178 4179显示当前窗口,使用Promise异步回调。 4180 4181> **说明:** 4182> 4183> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。 4184 4185**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4186 4187**返回值:** 4188 4189| 类型 | 说明 | 4190| ------------------- | ------------------------- | 4191| Promise<void> | 无返回结果的Promise对象。 | 4192 4193**示例:** 4194 4195```js 4196let promise = windowClass.show(); 4197promise.then(()=> { 4198 console.info('Succeeded in showing the window.'); 4199}).catch((err)=>{ 4200 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 4201}); 4202``` 4203 4204### destroy<sup>(deprecated)</sup> 4205 4206destroy(callback: AsyncCallback<void>): void 4207 4208销毁当前窗口,使用callback异步回调。 4209 4210> **说明:** 4211> 4212> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。 4213 4214**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4215 4216**参数:** 4217 4218| 参数名 | 类型 | 必填 | 说明 | 4219| -------- | ------------------------- | ---- | ---------- | 4220| callback | AsyncCallback<void> | 是 | 回调函数。 | 4221 4222**示例:** 4223 4224```js 4225windowClass.destroy((err) => { 4226 if (err.code) { 4227 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 4228 return; 4229 } 4230 console.info('Succeeded in destroying the window.'); 4231}); 4232``` 4233 4234### destroy<sup>(deprecated)</sup> 4235 4236destroy(): Promise<void> 4237 4238销毁当前窗口,使用Promise异步回调。 4239 4240> **说明:** 4241> 4242> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。 4243 4244**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4245 4246**返回值:** 4247 4248| 类型 | 说明 | 4249| ------------------- | ------------------------- | 4250| Promise<void> | 无返回结果的Promise对象。 | 4251 4252**示例:** 4253 4254```js 4255let promise = windowClass.destroy(); 4256promise.then(()=> { 4257 console.info('Succeeded in destroying the window.'); 4258}).catch((err)=>{ 4259 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 4260}); 4261``` 4262 4263### moveTo<sup>(deprecated)</sup> 4264 4265moveTo(x: number, y: number, callback: AsyncCallback<void>): void 4266 4267移动窗口位置,使用callback异步回调。 4268 4269全屏模式窗口不支持该操作。 4270 4271> **说明:** 4272> 4273> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。 4274 4275**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4276 4277**参数:** 4278 4279| 参数名 | 类型 | 必填 | 说明 | 4280| -------- | ------------------------- | ---- | ------------------------------------------------- | 4281| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px。 | 4282| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px。 | 4283| callback | AsyncCallback<void> | 是 | 回调函数。 | 4284 4285**示例:** 4286 4287```js 4288windowClass.moveTo(300, 300, (err)=>{ 4289 if (err.code) { 4290 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 4291 return; 4292 } 4293 console.info('Succeeded in moving the window.'); 4294}); 4295``` 4296 4297### moveTo<sup>(deprecated)</sup> 4298 4299moveTo(x: number, y: number): Promise<void> 4300 4301移动窗口位置,使用Promise异步回调。 4302 4303全屏模式窗口不支持该操作。 4304 4305> **说明:** 4306> 4307> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。 4308 4309**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4310 4311**参数:** 4312 4313| 参数名 | 类型 | 必填 | 说明 | 4314| ------ | ------ | ---- | ------------------------------------------------- | 4315| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px。 | 4316| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px。 | 4317 4318**返回值:** 4319 4320| 类型 | 说明 | 4321| ------------------- | ------------------------- | 4322| Promise<void> | 无返回结果的Promise对象。 | 4323 4324**示例:** 4325 4326```js 4327let promise = windowClass.moveTo(300, 300); 4328promise.then(()=> { 4329 console.info('Succeeded in moving the window.'); 4330}).catch((err)=>{ 4331 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 4332}); 4333``` 4334 4335### resetSize<sup>(deprecated)</sup> 4336 4337resetSize(width: number, height: number, callback: AsyncCallback<void>): void 4338 4339改变当前窗口大小,使用callback异步回调。 4340 4341应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。 4342 4343系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 4344 4345设置的宽度与高度受到此约束限制。 4346 4347全屏模式窗口不支持该操作。 4348 4349> **说明:** 4350> 4351> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。 4352 4353**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4354 4355**参数:** 4356 4357| 参数名 | 类型 | 必填 | 说明 | 4358| -------- | ------------------------- | ---- | -------------------------- | 4359| width | number | 是 | 目标窗口的宽度,单位为px。 | 4360| height | number | 是 | 目标窗口的高度,单位为px。 | 4361| callback | AsyncCallback<void> | 是 | 回调函数。 | 4362 4363**示例:** 4364 4365```js 4366windowClass.resetSize(500, 1000, (err) => { 4367 if (err.code) { 4368 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 4369 return; 4370 } 4371 console.info('Succeeded in changing the window size.'); 4372}); 4373``` 4374 4375### resetSize<sup>(deprecated)</sup> 4376 4377resetSize(width: number, height: number): Promise<void> 4378 4379改变当前窗口大小,使用Promise异步回调。 4380 4381应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。 4382 4383系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 4384 4385设置的宽度与高度受到此约束限制。 4386 4387全屏模式窗口不支持该操作。 4388 4389> **说明:** 4390> 4391> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。 4392 4393**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4394 4395**参数:** 4396 4397| 参数名 | 类型 | 必填 | 说明 | 4398| ------ | ------ | ---- | -------------------------- | 4399| width | number | 是 | 目标窗口的宽度,单位为px。 | 4400| height | number | 是 | 目标窗口的高度,单位为px。 | 4401 4402**返回值:** 4403 4404| 类型 | 说明 | 4405| ------------------- | ------------------------- | 4406| Promise<void> | 无返回结果的Promise对象。 | 4407 4408**示例:** 4409 4410```js 4411let promise = windowClass.resetSize(500, 1000); 4412promise.then(()=> { 4413 console.info('Succeeded in changing the window size.'); 4414}).catch((err)=>{ 4415 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 4416}); 4417``` 4418 4419### setWindowType<sup>(deprecated)</sup> 4420 4421setWindowType(type: WindowType, callback: AsyncCallback<void>): void 4422 4423设置窗口类型,使用callback异步回调。 4424 4425**系统接口:** 此接口为系统接口。 4426 4427> **说明:** 4428> 4429> 从 API version 7开始支持,从API version 9开始废弃。 4430 4431**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4432 4433**参数:** 4434 4435| 参数名 | 类型 | 必填 | 说明 | 4436| -------- | ------------------------- | ---- | ---------- | 4437| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 4438| callback | AsyncCallback<void> | 是 | 回调函数。 | 4439 4440**示例:** 4441 4442```js 4443let type = window.WindowType.TYPE_APP; 4444windowClass.setWindowType(type, (err) => { 4445 if (err.code) { 4446 console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); 4447 return; 4448 } 4449 console.info('Succeeded in setting the window type.'); 4450}); 4451``` 4452 4453### setWindowType<sup>(deprecated)</sup> 4454 4455setWindowType(type: WindowType): Promise<void> 4456 4457设置窗口类型,使用Promise异步回调。 4458 4459**系统接口:** 此接口为系统接口。 4460 4461> **说明:** 4462> 4463> 从 API version 7开始支持,从API version 9开始废弃。 4464 4465**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4466 4467**参数:** 4468 4469| 参数名 | 类型 | 必填 | 说明 | 4470| ------ | ------------------------- | ---- | ---------- | 4471| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 4472 4473**返回值:** 4474 4475| 类型 | 说明 | 4476| ------------------- | ------------------------- | 4477| Promise<void> | 无返回结果的Promise对象。 | 4478 4479**示例:** 4480 4481```js 4482let type = window.WindowType.TYPE_APP; 4483let promise = windowClass.setWindowType(type); 4484promise.then(()=> { 4485 console.info('Succeeded in setting the window type.'); 4486}).catch((err)=>{ 4487 console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); 4488}); 4489``` 4490 4491### getProperties<sup>(deprecated)</sup> 4492 4493getProperties(callback: AsyncCallback<WindowProperties>): void 4494 4495获取当前窗口的属性,使用callback异步回调,返回WindowProperties。 4496 4497> **说明:** 4498> 4499> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 4500 4501**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4502 4503**参数:** 4504 4505| 参数名 | 类型 | 必填 | 说明 | 4506| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 4507| callback | AsyncCallback<[WindowProperties](#windowproperties)> | 是 | 回调函数。返回当前窗口属性。 | 4508 4509**示例:** 4510 4511```js 4512windowClass.getProperties((err, data) => { 4513 if (err.code) { 4514 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 4515 return; 4516 } 4517 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 4518}); 4519``` 4520 4521### getProperties<sup>(deprecated)</sup> 4522 4523getProperties(): Promise<WindowProperties> 4524 4525获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。 4526 4527> **说明:** 4528> 4529> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 4530 4531**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4532 4533**返回值:** 4534 4535| 类型 | 说明 | 4536| ---------------------------------------------------- | ------------------------------- | 4537| Promise<[WindowProperties](#windowproperties)> | Promise对象。返回当前窗口属性。 | 4538 4539**示例:** 4540 4541```js 4542let promise = windowClass.getProperties(); 4543promise.then((data)=> { 4544 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 4545}).catch((err)=>{ 4546 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 4547}); 4548``` 4549 4550### getAvoidArea<sup>(deprecated)</sup> 4551 4552getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 4553 4554获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 4555 4556> **说明:** 4557> 4558> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 4559 4560**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4561 4562**参数:** 4563 4564| 参数名 | 类型 | 必填 | 说明 | 4565| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 4566| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 4567| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回窗口内容规避区域。 | 4568 4569**示例:** 4570 4571```js 4572let type = window.AvoidAreaType.TYPE_SYSTEM; 4573windowClass.getAvoidArea(type, (err, data) => { 4574 if (err.code) { 4575 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 4576 return; 4577 } 4578 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 4579}); 4580``` 4581 4582### getAvoidArea<sup>(deprecated)</sup> 4583 4584getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 4585 4586获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 4587 4588> **说明:** 4589> 4590> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 4591 4592**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4593 4594**参数:** 4595 4596| 参数名 | 类型 | 必填 | 说明 | 4597| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 4598| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。| 4599 4600**返回值:** 4601 4602| 类型 | 说明 | 4603|-----------------------------------------| ----------------------------------- | 4604| Promise<[AvoidArea](#avoidarea7)> | Promise对象。返回窗口内容规避区域。 | 4605 4606**示例:** 4607 4608```js 4609let type = window.AvoidAreaType.TYPE_SYSTEM; 4610let promise = windowClass.getAvoidArea(type); 4611promise.then((data)=> { 4612 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 4613}).catch((err)=>{ 4614 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 4615}); 4616``` 4617 4618### setFullScreen<sup>(deprecated)</sup> 4619 4620setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 4621 4622设置是否为全屏状态,使用callback异步回调。 4623 4624> **说明:** 4625> 4626> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。 4627 4628**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4629 4630**参数:** 4631 4632| 参数名 | 类型 | 必填 | 说明 | 4633| ------------ | ------------------------- | ---- | ---------------------------------------------- | 4634| isFullScreen | boolean | 是 | 是否设为全屏状态(该全屏状态隐藏状态栏导航栏)。true表示全屏;false表示非全屏。 | 4635| callback | AsyncCallback<void> | 是 | 回调函数。 | 4636 4637**示例:** 4638 4639```js 4640let isFullScreen = true; 4641windowClass.setFullScreen(isFullScreen, (err) => { 4642 if (err.code) { 4643 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 4644 return; 4645 } 4646 console.info('Succeeded in enabling the full-screen mode.'); 4647}); 4648``` 4649 4650### setFullScreen<sup>(deprecated)</sup> 4651 4652setFullScreen(isFullScreen: boolean): Promise<void> 4653 4654设置是否为全屏状态,使用Promise异步回调。 4655 4656> **说明:** 4657> 4658> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。 4659 4660**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4661 4662**参数:** 4663 4664| 参数名 | 类型 | 必填 | 说明 | 4665| ------------ | ------- | ---- | ---------------------------------------------- | 4666| isFullScreen | boolean | 是 | 是否设为全屏状态(该全屏状态隐藏状态栏导航栏)。true表示全屏;false表示非全屏。 | 4667 4668**返回值:** 4669 4670| 类型 | 说明 | 4671| ------------------- | ------------------------- | 4672| Promise<void> | 无返回结果的Promise对象。 | 4673 4674**示例:** 4675 4676```js 4677let isFullScreen = true; 4678let promise = windowClass.setFullScreen(isFullScreen); 4679promise.then(()=> { 4680 console.info('Succeeded in enabling the full-screen mode.'); 4681}).catch((err)=>{ 4682 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 4683}); 4684``` 4685 4686### setLayoutFullScreen<sup>(deprecated)</sup> 4687 4688setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 4689 4690设置窗口的布局是否为全屏显示状态,使用callback异步回调。 4691 4692> **说明:** 4693> 4694> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。 4695 4696**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4697 4698**参数:** 4699 4700| 参数名 | 类型 | 必填 | 说明 | 4701| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 4702| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为全屏显示状态(该全屏状态下状态栏、导航栏仍然显示)。true表示全屏;false表示非全屏。 | 4703| callback | AsyncCallback<void> | 是 | 回调函数。 | 4704 4705**示例:** 4706 4707```js 4708let isLayoutFullScreen= true; 4709windowClass.setLayoutFullScreen(isLayoutFullScreen, (err) => { 4710 if (err.code) { 4711 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 4712 return; 4713 } 4714 console.info('Succeeded in setting the window layout to full-screen mode.'); 4715}); 4716``` 4717 4718### setLayoutFullScreen<sup>(deprecated)</sup> 4719 4720setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 4721 4722设置窗口的布局是否为全屏显示状态,使用Promise异步回调。 4723 4724> **说明:** 4725> 4726> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。 4727 4728**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4729 4730**参数:** 4731 4732| 参数名 | 类型 | 必填 | 说明 | 4733| ------------------ | ------- | ---- | ------------------------------------------------------------ | 4734| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为全屏显示状态(该全屏状态下状态栏、导航栏仍然显示)。true表示全屏;false表示非全屏。 | 4735 4736**返回值:** 4737 4738| 类型 | 说明 | 4739| ------------------- | ------------------------- | 4740| Promise<void> | 无返回结果的Promise对象。 | 4741 4742**示例:** 4743 4744```js 4745let isLayoutFullScreen = true; 4746let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 4747promise.then(()=> { 4748 console.info('Succeeded in setting the window layout to full-screen mode.'); 4749}).catch((err)=>{ 4750 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 4751}); 4752``` 4753 4754### setSystemBarEnable<sup>(deprecated)</sup> 4755 4756setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 4757 4758设置导航栏、状态栏的可见模式,使用callback异步回调。 4759 4760> **说明:** 4761> 4762> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。 4763 4764**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4765 4766**参数:** 4767 4768| 参数名 | 类型 | 必填 | 说明 | 4769| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 4770| names | Array<'status'\|'navigation'> | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 4771| callback | AsyncCallback<void> | 是 | 回调函数。 | 4772 4773**示例:** 4774 4775```js 4776// 此处以不显示导航栏、状态栏为例 4777let names = []; 4778windowClass.setSystemBarEnable(names, (err) => { 4779 if (err.code) { 4780 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 4781 return; 4782 } 4783 console.info('Succeeded in setting the system bar to be invisible.'); 4784}); 4785``` 4786 4787### setSystemBarEnable<sup>(deprecated)</sup> 4788 4789setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 4790 4791设置导航栏、状态栏的可见模式,使用Promise异步回调。 4792 4793> **说明:** 4794> 4795> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。 4796 4797**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4798 4799**参数:** 4800 4801| 参数名 | 类型 | 必填 | 说明 | 4802| ------ | ---------------------------- | ---- | ------------------------ | 4803| names | Array<'status'\|'navigation'> | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 4804 4805**返回值:** 4806 4807| 类型 | 说明 | 4808| ------------------- | ------------------------- | 4809| Promise<void> | 无返回结果的Promise对象。 | 4810 4811**示例:** 4812 4813```js 4814// 此处以不显示导航栏、状态栏为例 4815let names = []; 4816let promise = windowClass.setSystemBarEnable(names); 4817promise.then(()=> { 4818 console.info('Succeeded in setting the system bar to be invisible.'); 4819}).catch((err)=>{ 4820 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 4821}); 4822``` 4823 4824### setSystemBarProperties<sup>(deprecated)</sup> 4825 4826setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 4827 4828设置窗口内导航栏、状态栏的属性,使用callback异步回调。 4829 4830> **说明:** 4831> 4832> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。 4833 4834**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4835 4836**参数:** 4837 4838| 参数名 | 类型 | 必填 | 说明 | 4839| ------------------- | ------------------------------------------- | ---- | ---------------------- | 4840| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 4841| callback | AsyncCallback<void> | 是 | 回调函数。 | 4842 4843**示例:** 4844 4845```js 4846let SystemBarProperties={ 4847 statusBarColor: '#ff00ff', 4848 navigationBarColor: '#00ff00', 4849 //以下两个属性从API Version8开始支持 4850 statusBarContentColor:'#ffffff', 4851 navigationBarContentColor:'#00ffff' 4852}; 4853windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 4854 if (err.code) { 4855 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 4856 return; 4857 } 4858 console.info('Succeeded in setting the system bar properties.'); 4859}); 4860``` 4861 4862### setSystemBarProperties<sup>(deprecated)</sup> 4863 4864setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 4865 4866设置窗口内导航栏、状态栏的属性,使用Promise异步回调。 4867 4868> **说明:** 4869> 4870> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。 4871 4872**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4873 4874**参数:** 4875 4876| 参数名 | 类型 | 必填 | 说明 | 4877| ------------------- | ------------------------------------------- | ---- | ---------------------- | 4878| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 4879 4880**返回值:** 4881 4882| 类型 | 说明 | 4883| ------------------- | ------------------------- | 4884| Promise<void> | 无返回结果的Promise对象。 | 4885 4886**示例:** 4887 4888```js 4889let SystemBarProperties={ 4890 statusBarColor: '#ff00ff', 4891 navigationBarColor: '#00ff00', 4892 //以下两个属性从API Version8开始支持 4893 statusBarContentColor:'#ffffff', 4894 navigationBarContentColor:'#00ffff' 4895}; 4896let promise = windowClass.setSystemBarProperties(SystemBarProperties); 4897promise.then(()=> { 4898 console.info('Succeeded in setting the system bar properties.'); 4899}).catch((err)=>{ 4900 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 4901}); 4902``` 4903 4904### loadContent<sup>(deprecated)</sup> 4905 4906loadContent(path: string, callback: AsyncCallback<void>): void 4907 4908为当前窗口加载具体页面内容,使用callback异步回调。 4909 4910> **说明:** 4911> 4912> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。 4913 4914**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4915 4916**参数:** 4917 4918| 参数名 | 类型 | 必填 | 说明 | 4919| -------- | ------------------------- | ---- | -------------------- | 4920| path | string | 是 | 设置加载页面的路径。 | 4921| callback | AsyncCallback<void> | 是 | 回调函数。 | 4922 4923**示例:** 4924 4925```js 4926windowClass.loadContent('pages/page2/page2', (err) => { 4927 if (err.code) { 4928 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 4929 return; 4930 } 4931 console.info('Succeeded in loading the content.'); 4932}); 4933``` 4934 4935### loadContent<sup>(deprecated)</sup> 4936 4937loadContent(path: string): Promise<void> 4938 4939为当前窗口加载具体页面内容,使用Promise异步回调。 4940 4941> **说明:** 4942> 4943> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。 4944 4945**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4946 4947**参数:** 4948 4949| 参数名 | 类型 | 必填 | 说明 | 4950| ------ | ------ | ---- | -------------------- | 4951| path | string | 是 | 设置加载页面的路径。 | 4952 4953**返回值:** 4954 4955| 类型 | 说明 | 4956| ------------------- | ------------------------- | 4957| Promise<void> | 无返回结果的Promise对象。 | 4958 4959**示例:** 4960 4961```js 4962let promise = windowClass.loadContent('pages/page2/page2'); 4963promise.then(()=> { 4964 console.info('Succeeded in loading the content.'); 4965}).catch((err)=>{ 4966 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 4967}); 4968``` 4969 4970### isShowing<sup>(deprecated)</sup> 4971 4972isShowing(callback: AsyncCallback<boolean>): void 4973 4974判断当前窗口是否已显示,使用callback异步回调。 4975 4976> **说明:** 4977> 4978> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 4979 4980**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4981 4982**参数:** 4983 4984| 参数名 | 类型 | 必填 | 说明 | 4985| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 4986| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 4987 4988**示例:** 4989 4990```js 4991windowClass.isShowing((err, data) => { 4992 if (err.code) { 4993 console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err)); 4994 return; 4995 } 4996 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 4997}); 4998``` 4999 5000### isShowing<sup>(deprecated)</sup> 5001 5002isShowing(): Promise<boolean> 5003 5004判断当前窗口是否已显示,使用Promise异步回调。 5005 5006> **说明:** 5007> 5008> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 5009 5010**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5011 5012**返回值:** 5013 5014| 类型 | 说明 | 5015| ---------------------- | ------------------------------------------------------------ | 5016| Promise<boolean> | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 5017 5018**示例:** 5019 5020```js 5021let promise = windowClass.isShowing(); 5022promise.then((data)=> { 5023 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 5024}).catch((err)=>{ 5025 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err)); 5026}); 5027``` 5028 5029### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 5030 5031on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 5032 5033开启系统规避区变化的监听。 5034 5035> **说明:** 5036> 5037> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。 5038 5039**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5040 5041**参数:** 5042 5043| 参数名 | 类型 | 必填 | 说明 | 5044| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 5045| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 5046| callback | Callback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回当前规避区。 | 5047 5048**示例:** 5049 5050```js 5051windowClass.on('systemAvoidAreaChange', (data) => { 5052 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 5053}); 5054``` 5055 5056### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 5057 5058off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 5059 5060关闭系统规避区变化的监听。 5061 5062> **说明:** 5063> 5064> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。 5065 5066**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5067 5068**参数:** 5069 5070| 参数名 | 类型 | 必填 | 说明 | 5071| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 5072| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 5073| callback | Callback<[AvoidArea](#avoidarea7)> | 否 | 回调函数。返回当前规避区。 | 5074 5075**示例:** 5076 5077```js 5078windowClass.off('systemAvoidAreaChange'); 5079``` 5080 5081### isSupportWideGamut<sup>(deprecated)</sup> 5082 5083isSupportWideGamut(callback: AsyncCallback<boolean>): void 5084 5085判断当前窗口是否支持广色域模式,使用callback异步回调。 5086 5087> **说明:** 5088> 5089> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。 5090 5091**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5092 5093**参数:** 5094 5095| 参数名 | 类型 | 必填 | 说明 | 5096| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 5097| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 5098 5099**示例:** 5100 5101```js 5102windowClass.isSupportWideGamut((err, data) => { 5103 if (err.code) { 5104 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 5105 return; 5106 } 5107 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 5108}); 5109``` 5110 5111### isSupportWideGamut<sup>(deprecated)</sup> 5112 5113isSupportWideGamut(): Promise<boolean> 5114 5115判断当前窗口是否支持广色域模式,使用Promise异步回调。 5116 5117> **说明:** 5118> 5119> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。 5120 5121**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5122 5123**返回值:** 5124 5125| 类型 | 说明 | 5126| ---------------------- | ------------------------------------------------------------ | 5127| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 5128 5129**示例:** 5130 5131```js 5132let promise = windowClass.isSupportWideGamut(); 5133promise.then((data)=> { 5134 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 5135}).catch((err)=>{ 5136 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 5137}); 5138``` 5139 5140### setColorSpace<sup>(deprecated)</sup> 5141 5142setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 5143 5144设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 5145 5146> **说明:** 5147> 5148> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。 5149 5150**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5151 5152**参数:** 5153 5154| 参数名 | 类型 | 必填 | 说明 | 5155| ---------- | ------------------------- | ---- | ------------ | 5156| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 5157| callback | AsyncCallback<void> | 是 | 回调函数。 | 5158 5159**示例:** 5160 5161```js 5162windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err) => { 5163 if (err.code) { 5164 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 5165 return; 5166 } 5167 console.info('Succeeded in setting window colorspace.'); 5168}); 5169``` 5170 5171### setColorSpace<sup>(deprecated)</sup> 5172 5173setColorSpace(colorSpace:ColorSpace): Promise<void> 5174 5175设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 5176 5177> **说明:** 5178> 5179> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。 5180 5181**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5182 5183**参数:** 5184 5185| 参数名 | 类型 | 必填 | 说明 | 5186| ---------- | ------------------------- | ---- | -------------- | 5187| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 5188 5189**返回值:** 5190 5191| 类型 | 说明 | 5192| ------------------- | ------------------------- | 5193| Promise<void> | 无返回结果的Promise对象。 | 5194 5195**示例:** 5196 5197```js 5198let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 5199promise.then(()=> { 5200 console.info('Succeeded in setting window colorspace.'); 5201}).catch((err)=>{ 5202 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 5203}); 5204``` 5205 5206### getColorSpace<sup>(deprecated)</sup> 5207 5208getColorSpace(callback: AsyncCallback<ColorSpace>): void 5209 5210获取当前窗口色域模式,使用callback异步回调。 5211 5212> **说明:** 5213> 5214> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 5215 5216**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5217 5218**参数:** 5219 5220| 参数名 | 类型 | 必填 | 说明 | 5221| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 5222| callback | AsyncCallback<[ColorSpace](#colorspace8)> | 是 | 回调函数。当获取成功,err为undefined,data为当前色域模式。 | 5223 5224**示例:** 5225 5226```js 5227windowClass.getColorSpace((err, data) => { 5228 if (err.code) { 5229 console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err)); 5230 return; 5231 } 5232 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 5233}); 5234``` 5235 5236### getColorSpace<sup>(deprecated)</sup> 5237 5238getColorSpace(): Promise<ColorSpace> 5239 5240获取当前窗口色域模式,使用Promise异步回调。 5241 5242> **说明:** 5243> 5244> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 5245 5246**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5247 5248**返回值:** 5249 5250| 类型 | 说明 | 5251| ---------------------------------------- | ------------------------------- | 5252| Promise<[ColorSpace](#colorspace8)> | Promise对象。返回当前色域模式。 | 5253 5254**示例:** 5255 5256```js 5257let promise = windowClass.getColorSpace(); 5258promise.then((data)=> { 5259 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 5260}).catch((err)=>{ 5261 console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err)); 5262}); 5263``` 5264 5265### setBackgroundColor<sup>(deprecated)</sup> 5266 5267setBackgroundColor(color: string, callback: AsyncCallback<void>): void 5268 5269设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent](#loadcontent9)或[setUIContent()](#setuicontent9)之后使用。 5270 5271> **说明:** 5272> 5273> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 5274 5275**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5276 5277**参数:** 5278 5279| 参数名 | 类型 | 必填 | 说明 | 5280| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 5281| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 5282| callback | AsyncCallback<void> | 是 | 回调函数。 | 5283 5284**示例:** 5285 5286```js 5287let color = '#00ff33'; 5288windowClass.setBackgroundColor(color, (err) => { 5289 if (err.code) { 5290 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 5291 return; 5292 } 5293 console.info('Succeeded in setting the background color.'); 5294}); 5295``` 5296 5297### setBackgroundColor<sup>(deprecated)</sup> 5298 5299setBackgroundColor(color: string): Promise<void> 5300 5301设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent](#loadcontent9)或[setUIContent()](#setuicontent9)之后使用。 5302 5303> **说明:** 5304> 5305> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 5306 5307**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5308 5309**参数:** 5310 5311| 参数名 | 类型 | 必填 | 说明 | 5312| ------ | ------ | ---- | ------------------------------------------------------------ | 5313| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 5314 5315**返回值:** 5316 5317| 类型 | 说明 | 5318| ------------------- | ------------------------- | 5319| Promise<void> | 无返回结果的Promise对象。 | 5320 5321**示例:** 5322 5323```js 5324let color = '#00ff33'; 5325let promise = windowClass.setBackgroundColor(color); 5326promise.then(()=> { 5327 console.info('Succeeded in setting the background color.'); 5328}).catch((err)=>{ 5329 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 5330}); 5331``` 5332 5333### setBrightness<sup>(deprecated)</sup> 5334 5335setBrightness(brightness: number, callback: AsyncCallback<void>): void 5336 5337设置屏幕亮度值,使用callback异步回调。 5338 5339> **说明:** 5340> 5341> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。 5342 5343**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5344 5345**参数:** 5346 5347| 参数名 | 类型 | 必填 | 说明 | 5348| ---------- | ------------------------- | ---- | ------------------------------------ | 5349| brightness | number | 是 | 屏幕亮度值,值为0-1之间。1表示最亮。 | 5350| callback | AsyncCallback<void> | 是 | 回调函数。 | 5351 5352**示例:** 5353 5354```js 5355let brightness = 1; 5356windowClass.setBrightness(brightness, (err) => { 5357 if (err.code) { 5358 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 5359 return; 5360 } 5361 console.info('Succeeded in setting the brightness.'); 5362}); 5363``` 5364 5365### setBrightness<sup>(deprecated)</sup> 5366 5367setBrightness(brightness: number): Promise<void> 5368 5369设置屏幕亮度值,使用Promise异步回调。 5370 5371> **说明:** 5372> 5373> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。 5374 5375**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5376 5377**参数:** 5378 5379| 参数名 | 类型 | 必填 | 说明 | 5380| ---------- | ------ | ---- | ------------------------------------ | 5381| brightness | number | 是 | 屏幕亮度值,值为0-1之间。1表示最亮。 | 5382 5383**返回值:** 5384 5385| 类型 | 说明 | 5386| ------------------- | ------------------------- | 5387| Promise<void> | 无返回结果的Promise对象。 | 5388 5389**示例:** 5390 5391```js 5392let brightness = 1; 5393let promise = windowClass.setBrightness(brightness); 5394promise.then(()=> { 5395 console.info('Succeeded in setting the brightness.'); 5396}).catch((err)=>{ 5397 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 5398}); 5399``` 5400 5401### setDimBehind<sup>(deprecated)</sup> 5402 5403setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 5404 5405窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。 5406 5407> **说明:** 5408> 5409> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 5410 5411**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5412 5413**参数:** 5414 5415| 参数名 | 类型 | 必填 | 说明 | 5416| -------------- | ------------------------- | ---- | -------------------------------------------------- | 5417| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | 5418| callback | AsyncCallback<void> | 是 | 回调函数。 | 5419 5420**示例:** 5421 5422```js 5423windowClass.setDimBehind(0.5, (err) => { 5424 if (err.code) { 5425 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 5426 return; 5427 } 5428 console.info('Succeeded in setting the dimness.'); 5429}); 5430``` 5431 5432### setDimBehind<sup>(deprecated)</sup> 5433 5434setDimBehind(dimBehindValue: number): Promise<void> 5435 5436窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。 5437 5438> **说明:** 5439> 5440> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 5441 5442**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5443 5444**参数:** 5445 5446| 参数名 | 类型 | 必填 | 说明 | 5447| -------------- | ------ | ---- | -------------------------------------------------- | 5448| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | 5449 5450**返回值:** 5451 5452| 类型 | 说明 | 5453| ------------------- | ------------------------- | 5454| Promise<void> | 无返回结果的Promise对象。 | 5455 5456**示例:** 5457 5458```js 5459let promise = windowClass.setDimBehind(0.5); 5460promise.then(()=> { 5461 console.info('Succeeded in setting the dimness.'); 5462}).catch((err)=>{ 5463 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 5464}); 5465``` 5466 5467### setFocusable<sup>(deprecated)</sup> 5468 5469setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 5470 5471设置点击时是否支持切换焦点窗口,使用callback异步回调。 5472 5473> **说明:** 5474> 5475> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。 5476 5477**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5478 5479**参数:** 5480 5481| 参数名 | 类型 | 必填 | 说明 | 5482| ----------- | ------------------------- | ---- | ---------------------------- | 5483| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 5484| callback | AsyncCallback<void> | 是 | 回调函数。 | 5485 5486**示例:** 5487 5488```js 5489let isFocusable= true; 5490windowClass.setFocusable(isFocusable, (err) => { 5491 if (err.code) { 5492 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 5493 return; 5494 } 5495 console.info('Succeeded in setting the window to be focusable.'); 5496}); 5497``` 5498 5499### setFocusable<sup>(deprecated)</sup> 5500 5501setFocusable(isFocusable: boolean): Promise<void> 5502 5503设置点击时是否支持切换焦点窗口,使用Promise异步回调。 5504 5505> **说明:** 5506> 5507> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。 5508 5509**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5510 5511**参数:** 5512 5513| 参数名 | 类型 | 必填 | 说明 | 5514| ----------- | ------- | ---- | ---------------------------- | 5515| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 5516 5517**返回值:** 5518 5519| 类型 | 说明 | 5520| ------------------- | ------------------------- | 5521| Promise<void> | 无返回结果的Promise对象。 | 5522 5523**示例:** 5524 5525```js 5526let isFocusable= true; 5527let promise = windowClass.setFocusable(isFocusable); 5528promise.then(()=> { 5529 console.info('Succeeded in setting the window to be focusable.'); 5530}).catch((err)=>{ 5531 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 5532}); 5533``` 5534 5535### setKeepScreenOn<sup>(deprecated)</sup> 5536 5537setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 5538 5539设置屏幕是否为常亮状态,使用callback异步回调。 5540 5541> **说明:** 5542> 5543> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。 5544 5545**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5546 5547**参数:** 5548 5549| 参数名 | 类型 | 必填 | 说明 | 5550| -------------- | ------------------------- | ---- | ------------------------ | 5551| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 5552| callback | AsyncCallback<void> | 是 | 回调函数。 | 5553 5554**示例:** 5555 5556```js 5557let isKeepScreenOn = true; 5558windowClass.setKeepScreenOn(isKeepScreenOn, (err) => { 5559 if (err.code) { 5560 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 5561 return; 5562 } 5563 console.info('Succeeded in setting the screen to be always on.'); 5564}); 5565``` 5566 5567### setKeepScreenOn<sup>(deprecated)</sup> 5568 5569setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 5570 5571设置屏幕是否为常亮状态,使用Promise异步回调。 5572 5573> **说明:** 5574> 5575> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。 5576 5577**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5578 5579**参数:** 5580 5581| 参数名 | 类型 | 必填 | 说明 | 5582| -------------- | ------- | ---- | ------------------------ | 5583| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 5584 5585**返回值:** 5586 5587| 类型 | 说明 | 5588| ------------------- | ------------------------- | 5589| Promise<void> | 无返回结果的Promise对象。 | 5590 5591**示例:** 5592 5593```js 5594let isKeepScreenOn = true; 5595let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 5596promise.then(() => { 5597 console.info('Succeeded in setting the screen to be always on.'); 5598}).catch((err)=>{ 5599 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 5600}); 5601``` 5602 5603### setOutsideTouchable<sup>(deprecated)</sup> 5604 5605setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 5606 5607设置是否允许可点击子窗口之外的区域,使用callback异步回调。 5608 5609> **说明:** 5610> 5611> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 5612 5613**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5614 5615**参数:** 5616 5617| 参数名 | 类型 | 必填 | 说明 | 5618| --------- | ------------------------- | ---- | ---------------- | 5619| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 5620| callback | AsyncCallback<void> | 是 | 回调函数。 | 5621 5622**示例:** 5623 5624```js 5625windowClass.setOutsideTouchable(true, (err) => { 5626 if (err.code) { 5627 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 5628 return; 5629 } 5630 console.info('Succeeded in setting the area to be touchable.'); 5631}); 5632``` 5633 5634### setOutsideTouchable<sup>(deprecated)</sup> 5635 5636setOutsideTouchable(touchable: boolean): Promise<void> 5637 5638设置是否允许可点击子窗口之外的区域,使用Promise异步回调。。 5639 5640> **说明:** 5641> 5642> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 5643 5644**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5645 5646**参数:** 5647 5648| 参数名 | 类型 | 必填 | 说明 | 5649| --------- | ------- | ---- | ---------------- | 5650| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 5651 5652**返回值:** 5653 5654| 类型 | 说明 | 5655| ------------------- | ------------------------- | 5656| Promise<void> | 无返回结果的Promise对象。 | 5657 5658**示例:** 5659 5660```js 5661let promise = windowClass.setOutsideTouchable(true); 5662promise.then(()=> { 5663 console.info('Succeeded in setting the area to be touchable.'); 5664}).catch((err)=>{ 5665 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 5666}); 5667``` 5668 5669### setPrivacyMode<sup>(deprecated)</sup> 5670 5671setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 5672 5673设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。 5674 5675> **说明:** 5676> 5677> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。 5678 5679**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5680 5681**参数:** 5682 5683| 参数名 | 类型 | 必填 | 说明 | 5684| ------------- | ------------------------- | ---- | -------------------- | 5685| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 5686| callback | AsyncCallback<void> | 是 | 回调函数。 | 5687 5688**示例:** 5689 5690```js 5691let isPrivacyMode = true; 5692windowClass.setPrivacyMode(isPrivacyMode, (err) => { 5693 if (err.code) { 5694 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 5695 return; 5696 } 5697 console.info('Succeeded in setting the window to privacy mode.'); 5698}); 5699``` 5700 5701### setPrivacyMode<sup>(deprecated)</sup> 5702 5703setPrivacyMode(isPrivacyMode: boolean): Promise<void> 5704 5705设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。 5706 5707> **说明:** 5708> 5709> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。 5710 5711**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5712 5713**参数:** 5714 5715| 参数名 | 类型 | 必填 | 说明 | 5716| ------------- | ------- | ---- | -------------------- | 5717| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 5718 5719**返回值:** 5720 5721| 类型 | 说明 | 5722| ------------------- | ------------------------- | 5723| Promise<void> | 无返回结果的Promise对象。 | 5724 5725**示例:** 5726 5727```js 5728let isPrivacyMode = true; 5729let promise = windowClass.setPrivacyMode(isPrivacyMode); 5730promise.then(()=> { 5731 console.info('Succeeded in setting the window to privacy mode.'); 5732}).catch((err)=>{ 5733 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 5734}); 5735``` 5736 5737### setTouchable<sup>(deprecated)</sup> 5738 5739setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 5740 5741设置窗口是否为可触状态,使用callback异步回调。 5742 5743> **说明:** 5744> 5745> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。 5746 5747**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5748 5749**参数:** 5750 5751| 参数名 | 类型 | 必填 | 说明 | 5752| ----------- | ------------------------- | ---- | -------------------- | 5753| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 5754| callback | AsyncCallback<void> | 是 | 回调函数。 | 5755 5756**示例:** 5757 5758```js 5759let isTouchable = true; 5760windowClass.setTouchable(isTouchable, (err) => { 5761 if (err.code) { 5762 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 5763 return; 5764 } 5765 console.info('Succeeded in setting the window to be touchable.'); 5766}); 5767``` 5768 5769### setTouchable<sup>(deprecated)</sup> 5770 5771setTouchable(isTouchable: boolean): Promise<void> 5772 5773设置窗口是否为可触状态,使用Promise异步回调。 5774 5775> **说明:** 5776> 5777> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。 5778 5779**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5780 5781**参数:** 5782 5783| 参数名 | 类型 | 必填 | 说明 | 5784| ----------- | ------- | ---- | -------------------- | 5785| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 5786 5787**返回值:** 5788 5789| 类型 | 说明 | 5790| ------------------- | ------------------------- | 5791| Promise<void> | 无返回结果的Promise对象。 | 5792 5793**示例:** 5794 5795```js 5796let isTouchable = true; 5797let promise = windowClass.setTouchable(isTouchable); 5798promise.then(()=> { 5799 console.info('Succeeded in setting the window to be touchable.'); 5800}).catch((err)=>{ 5801 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 5802}); 5803``` 5804 5805## WindowStageEventType<sup>9+</sup> 5806 5807WindowStage生命周期。 5808 5809**模型约束:** 此接口仅可在Stage模型下使用。 5810 5811**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5812 5813| 名称 | 值 | 说明 | 5814| ---------- | ------ | ---------- | 5815| SHOWN | 1 | 切到前台。 | 5816| ACTIVE | 2 | 获焦状态。 | 5817| INACTIVE | 3 | 失焦状态。 | 5818| HIDDEN | 4 | 切到后台。 | 5819 5820## WindowStage<sup>9+</sup> 5821 5822窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 5823 5824下列API示例中都需在[onWindowStageCreate()](js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 5825 5826### getMainWindow<sup>9+</sup> 5827 5828getMainWindow(callback: AsyncCallback<Window>): void 5829 5830获取该WindowStage实例下的主窗口,使用callback异步回调。 5831 5832**模型约束:** 此接口仅可在Stage模型下使用。 5833 5834**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5835 5836**参数:** 5837 5838| 参数名 | 类型 | 必填 | 说明 | 5839| -------- | -------------------------------------- | ---- | --------------------------------------------- | 5840| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的主窗口对象。 | 5841 5842**错误码:** 5843 5844以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5845 5846| 错误码ID | 错误信息 | 5847| ------- | ------------------------------ | 5848| 1300002 | This window state is abnormal. | 5849| 1300005 | This window stage is abnormal. | 5850 5851**示例:** 5852 5853```ts 5854import UIAbility from '@ohos.app.ability.UIAbility'; 5855 5856class myAbility extends UIAbility { 5857 onWindowStageCreate(windowStage) { 5858 console.log('onWindowStageCreate'); 5859 let windowClass = null; 5860 windowStage.getMainWindow((err, data) => { 5861 if (err.code) { 5862 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5863 return; 5864 } 5865 windowClass = data; 5866 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5867 }); 5868 } 5869}; 5870``` 5871 5872### getMainWindow<sup>9+</sup> 5873 5874getMainWindow(): Promise<Window> 5875 5876获取该WindowStage实例下的主窗口,使用Promise异步回调。 5877 5878**模型约束:** 此接口仅可在Stage模型下使用。 5879 5880**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5881 5882**返回值:** 5883 5884| 类型 | 说明 | 5885| -------------------------------- | ------------------------------------------------ | 5886| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的主窗口对象。 | 5887 5888**错误码:** 5889 5890以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5891 5892| 错误码ID | 错误信息 | 5893| ------- | ------------------------------ | 5894| 1300002 | This window state is abnormal. | 5895| 1300005 | This window stage is abnormal. | 5896 5897**示例:** 5898 5899```ts 5900import UIAbility from '@ohos.app.ability.UIAbility'; 5901 5902class myAbility extends UIAbility { 5903 onWindowStageCreate(windowStage) { 5904 console.log('onWindowStageCreate'); 5905 let windowClass = null; 5906 let promise = windowStage.getMainWindow(); 5907 promise.then((data) => { 5908 windowClass = data; 5909 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5910 }).catch((err) => { 5911 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5912 }); 5913 } 5914}; 5915``` 5916 5917### getMainWindowSync<sup>9+</sup> 5918 5919getMainWindowSync(): Window 5920 5921获取该WindowStage实例下的主窗口。 5922 5923**模型约束:** 此接口仅可在Stage模型下使用。 5924 5925**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5926 5927**返回值:** 5928 5929| 类型 | 说明 | 5930| ----------------- | --------------------------------- | 5931| [Window](#window) | 返回当前WindowStage下的主窗口对象。 | 5932 5933**错误码:** 5934 5935以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5936 5937| 错误码ID | 错误信息 | 5938| ------- | ------------------------------ | 5939| 1300002 | This window state is abnormal. | 5940| 1300005 | This window stage is abnormal. | 5941 5942**示例:** 5943 5944```ts 5945import UIAbility from '@ohos.app.ability.UIAbility'; 5946 5947class myAbility extends UIAbility { 5948 onWindowStageCreate(windowStage) { 5949 console.log('onWindowStageCreate'); 5950 try { 5951 let windowClass = windowStage.getMainWindowSync(); 5952 } catch (exception) { 5953 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception)); 5954 }; 5955 } 5956}; 5957``` 5958 5959### createSubWindow<sup>9+</sup> 5960 5961createSubWindow(name: string, callback: AsyncCallback<Window>): void 5962 5963创建该WindowStage实例下的子窗口,使用callback异步回调。 5964 5965**模型约束:** 此接口仅可在Stage模型下使用。 5966 5967**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5968 5969**参数:** 5970 5971| 参数名 | 类型 | 必填 | 说明 | 5972| -------- | -------------------------------------- | ---- | --------------------------------------------- | 5973| name | string | 是 | 子窗口的名字。 | 5974| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的子窗口对象。 | 5975 5976**错误码:** 5977 5978以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5979 5980| 错误码ID | 错误信息 | 5981| ------- | ------------------------------ | 5982| 1300002 | This window state is abnormal. | 5983| 1300005 | This window stage is abnormal. | 5984 5985**示例:** 5986 5987```ts 5988import UIAbility from '@ohos.app.ability.UIAbility'; 5989 5990class myAbility extends UIAbility { 5991 onWindowStageCreate(windowStage) { 5992 console.log('onWindowStageCreate'); 5993 let windowClass = null; 5994 try { 5995 windowStage.createSubWindow('mySubWindow', (err, data) => { 5996 if (err.code) { 5997 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 5998 return; 5999 } 6000 windowClass = data; 6001 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 6002 windowClass.resetSize(500, 1000); 6003 }); 6004 } catch (exception) { 6005 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 6006 }; 6007 } 6008}; 6009``` 6010### createSubWindow<sup>9+</sup> 6011 6012createSubWindow(name: string): Promise<Window> 6013 6014创建该WindowStage实例下的子窗口,使用Promise异步回调。 6015 6016**模型约束:** 此接口仅可在Stage模型下使用。 6017 6018**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6019 6020**参数:** 6021 6022| 参数名 | 类型 | 必填 | 说明 | 6023| ------ | ------ | ---- | -------------- | 6024| name | string | 是 | 子窗口的名字。 | 6025 6026**返回值:** 6027 6028| 类型 | 说明 | 6029| -------------------------------- | ------------------------------------------------ | 6030| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的子窗口对象。 | 6031 6032**错误码:** 6033 6034以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6035 6036| 错误码ID | 错误信息 | 6037| ------- | ------------------------------ | 6038| 1300002 | This window state is abnormal. | 6039| 1300005 | This window stage is abnormal. | 6040 6041**示例:** 6042 6043```ts 6044import UIAbility from '@ohos.app.ability.UIAbility'; 6045 6046class myAbility extends UIAbility { 6047 onWindowStageCreate(windowStage) { 6048 console.log('onWindowStageCreate'); 6049 let windowClass = null; 6050 try { 6051 let promise = windowStage.createSubWindow('mySubWindow'); 6052 promise.then((data) => { 6053 windowClass = data; 6054 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 6055 }).catch((err) => { 6056 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 6057 }); 6058 } catch (exception) { 6059 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 6060 }; 6061 } 6062}; 6063``` 6064 6065### getSubWindow<sup>9+</sup> 6066 6067getSubWindow(callback: AsyncCallback<Array<Window>>): void 6068 6069获取该WindowStage实例下的所有子窗口,使用callback异步回调。 6070 6071**模型约束:** 此接口仅可在Stage模型下使用。 6072 6073**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6074 6075**参数:** 6076 6077| 参数名 | 类型 | 必填 | 说明 | 6078| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | 6079| callback | AsyncCallback<Array<[Window](#window)>> | 是 | 回调函数。返回当前WindowStage下的所有子窗口对象。 | 6080 6081**错误码:** 6082 6083以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6084 6085| 错误码ID | 错误信息 | 6086| ------- | ------------------------------ | 6087| 1300005 | This window stage is abnormal. | 6088 6089**示例:** 6090 6091```ts 6092import UIAbility from '@ohos.app.ability.UIAbility'; 6093 6094class myAbility extends UIAbility { 6095 onWindowStageCreate(windowStage) { 6096 console.log('onWindowStageCreate'); 6097 let windowClass = null; 6098 windowStage.getSubWindow((err, data) => { 6099 if (err.code) { 6100 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 6101 return; 6102 } 6103 windowClass = data; 6104 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 6105 }); 6106 } 6107}; 6108``` 6109### getSubWindow<sup>9+</sup> 6110 6111getSubWindow(): Promise<Array<Window>> 6112 6113获取该WindowStage实例下的所有子窗口,使用Promise异步回调。 6114 6115**模型约束:** 此接口仅可在Stage模型下使用。 6116 6117**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6118 6119**返回值:** 6120 6121| 类型 | 说明 | 6122| --------------------------------------------- | ---------------------------------------------------- | 6123| Promise<Array<[Window](#window)>> | Promise对象。返回当前WindowStage下的所有子窗口对象。 | 6124 6125**错误码:** 6126 6127以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6128 6129| 错误码ID | 错误信息 | 6130| ------- | ------------------------------ | 6131| 1300005 | This window stage is abnormal. | 6132 6133**示例:** 6134 6135```ts 6136import UIAbility from '@ohos.app.ability.UIAbility'; 6137 6138class myAbility extends UIAbility { 6139 onWindowStageCreate(windowStage) { 6140 console.log('onWindowStageCreate'); 6141 let windowClass = null; 6142 let promise = windowStage.getSubWindow(); 6143 promise.then((data) => { 6144 windowClass = data; 6145 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 6146 }).catch((err) => { 6147 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 6148 }) 6149 } 6150}; 6151``` 6152### loadContent<sup>9+</sup> 6153 6154loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 6155 6156为当前WindowStage的主窗口加载与LocalStorage相关联的具体页面内容,使用callback异步回调。 6157 6158**模型约束:** 此接口仅可在Stage模型下使用。 6159 6160**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6161 6162**参数:** 6163 6164| 参数名 | 类型 | 必填 | 说明 | 6165| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 6166| path | string | 是 | 设置加载页面的路径。 | 6167| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 | 6168| callback | AsyncCallback<void> | 是 | 回调函数。 | 6169 6170**错误码:** 6171 6172以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6173 6174| 错误码ID | 错误信息 | 6175| ------- | ------------------------------ | 6176| 1300002 | This window state is abnormal. | 6177| 1300005 | This window stage is abnormal. | 6178 6179**示例:** 6180 6181```ts 6182import UIAbility from '@ohos.app.ability.UIAbility'; 6183 6184class myAbility extends UIAbility { 6185 storage : LocalStorage 6186 onWindowStageCreate(windowStage) { 6187 this.storage = new LocalStorage(); 6188 this.storage.setOrCreate('storageSimpleProp',121); 6189 console.log('onWindowStageCreate'); 6190 try { 6191 windowStage.loadContent('pages/page2',this.storage,(err) => { 6192 if (err.code) { 6193 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6194 return; 6195 } 6196 console.info('Succeeded in loading the content.'); 6197 }); 6198 } catch (exception) { 6199 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6200 }; 6201 } 6202}; 6203``` 6204 6205### loadContent<sup>9+</sup> 6206 6207loadContent(path: string, storage?: LocalStorage): Promise<void> 6208 6209为当前WindowStage的主窗口加载与LocalStorage相关联的具体页面内容,使用Promise异步回调。 6210 6211**模型约束:** 此接口仅可在Stage模型下使用。 6212 6213**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6214 6215**参数:** 6216 6217| 参数名 | 类型 | 必填 | 说明 | 6218| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 6219| path | string | 是 | 设置加载页面的路径。 | 6220| storage | [LocalStorage](../../quick-start/arkts-state-mgmt-application-level.md#localstorage) | 否 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 | 6221 6222**返回值:** 6223 6224| 类型 | 说明 | 6225| ------------------- | ------------------------- | 6226| Promise<void> | 无返回结果的Promise对象。 | 6227 6228**错误码:** 6229 6230以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6231 6232| 错误码ID | 错误信息 | 6233| ------- | ------------------------------ | 6234| 1300002 | This window state is abnormal. | 6235| 1300005 | This window stage is abnormal. | 6236 6237**示例:** 6238 6239```ts 6240import UIAbility from '@ohos.app.ability.UIAbility'; 6241 6242class myAbility extends UIAbility { 6243 storage : LocalStorage 6244 onWindowStageCreate(windowStage) { 6245 this.storage = new LocalStorage(); 6246 this.storage.setOrCreate('storageSimpleProp',121); 6247 console.log('onWindowStageCreate'); 6248 try { 6249 let promise = windowStage.loadContent('pages/page2',this.storage); 6250 promise.then(() => { 6251 console.info('Succeeded in loading the content.'); 6252 }).catch((err) => { 6253 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6254 }); 6255 } catch (exception) { 6256 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6257 }; 6258 } 6259}; 6260``` 6261 6262### loadContent<sup>9+</sup> 6263 6264loadContent(path: string, callback: AsyncCallback<void>): void 6265 6266为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。 6267 6268**模型约束:** 此接口仅可在Stage模型下使用。 6269 6270**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6271 6272**参数:** 6273 6274| 参数名 | 类型 | 必填 | 说明 | 6275| -------- | ------------------------- | ---- | -------------------- | 6276| path | string | 是 | 设置加载页面的路径。 | 6277| callback | AsyncCallback<void> | 是 | 回调函数。 | 6278 6279**错误码:** 6280 6281以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6282 6283| 错误码ID | 错误信息 | 6284| ------- | ------------------------------ | 6285| 1300002 | This window state is abnormal. | 6286| 1300005 | This window stage is abnormal. | 6287 6288**示例:** 6289 6290```ts 6291import UIAbility from '@ohos.app.ability.UIAbility'; 6292 6293class myAbility extends UIAbility { 6294 onWindowStageCreate(windowStage) { 6295 console.log('onWindowStageCreate'); 6296 try { 6297 windowStage.loadContent('pages/page2', (err) => { 6298 if (err.code) { 6299 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6300 return; 6301 } 6302 console.info('Succeeded in loading the content.'); 6303 }); 6304 } catch (exception) { 6305 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 6306 }; 6307 } 6308}; 6309``` 6310 6311### on('windowStageEvent')<sup>9+</sup> 6312 6313on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 6314 6315开启WindowStage生命周期变化的监听。 6316 6317**模型约束:** 此接口仅可在Stage模型下使用。 6318 6319**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6320 6321**参数:** 6322 6323| 参数名 | 类型 | 必填 | 说明 | 6324| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6325| type | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 6326| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 是 | 回调函数。返回当前的WindowStage生命周期状态。 | 6327 6328**错误码:** 6329 6330以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6331 6332| 错误码ID | 错误信息 | 6333| ------- | ------------------------------ | 6334| 1300002 | This window state is abnormal. | 6335| 1300005 | This window stage is abnormal. | 6336 6337**示例:** 6338 6339```ts 6340import UIAbility from '@ohos.app.ability.UIAbility'; 6341 6342class myAbility extends UIAbility { 6343 onWindowStageCreate(windowStage) { 6344 console.log('onWindowStageCreate'); 6345 try { 6346 windowStage.on('windowStageEvent', (data) => { 6347 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 6348 JSON.stringify(data)); 6349 }); 6350 } catch (exception) { 6351 console.error('Failed to enable the listener for window stage event changes. Cause:' + 6352 JSON.stringify(exception)); 6353 }; 6354 } 6355}; 6356``` 6357 6358### off('windowStageEvent')<sup>9+</sup> 6359 6360off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 6361 6362关闭WindowStage生命周期变化的监听。 6363 6364**模型约束:** 此接口仅可在Stage模型下使用。 6365 6366**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6367 6368**参数:** 6369 6370| 参数名 | 类型 | 必填 | 说明 | 6371| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6372| type | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 6373| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 否 | 回调函数。返回当前的WindowStage生命周期状态。 | 6374 6375**错误码:** 6376 6377以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6378 6379| 错误码ID | 错误信息 | 6380| ------- | ------------------------------ | 6381| 1300002 | This window state is abnormal. | 6382| 1300005 | This window stage is abnormal. | 6383 6384**示例:** 6385 6386```ts 6387import UIAbility from '@ohos.app.ability.UIAbility'; 6388 6389class myAbility extends UIAbility { 6390 onWindowStageCreate(windowStage) { 6391 console.log('onWindowStageCreate'); 6392 try { 6393 windowStage.off('windowStageEvent'); 6394 } catch (exception) { 6395 console.error('Failed to disable the listener for window stage event changes. Cause:' + 6396 JSON.stringify(exception)); 6397 }; 6398 } 6399}; 6400``` 6401 6402### disableWindowDecor()<sup>9+</sup> 6403 6404disableWindowDecor(): void 6405 6406禁止窗口装饰。 6407 6408**模型约束:** 此接口仅可在Stage模型下使用。 6409 6410**系统接口:** 此接口为系统接口。 6411 6412**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6413 6414**错误码:** 6415 6416以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6417 6418| 错误码ID | 错误信息 | 6419| ------- | ------------------------------ | 6420| 1300002 | This window state is abnormal. | 6421| 1300005 | This window stage is abnormal. | 6422 6423**示例:** 6424 6425```ts 6426import UIAbility from '@ohos.app.ability.UIAbility'; 6427 6428class myAbility extends UIAbility { 6429 onWindowStageCreate(windowStage) { 6430 console.log('disableWindowDecor'); 6431 windowStage.disableWindowDecor(); 6432 } 6433}; 6434``` 6435 6436### setShowOnLockScreen()<sup>9+</sup> 6437 6438setShowOnLockScreen(showOnLockScreen: boolean): void 6439 6440设置应用显示在锁屏之上。 6441 6442**系统接口:** 此接口为系统接口。 6443 6444**模型约束:** 此接口仅可在Stage模型下使用。 6445 6446**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6447 6448**参数:** 6449 6450| 参数名 | 类型 | 必填 | 说明 | 6451| ---------------- | ------- | ---- | ---------------------------- | 6452| showOnLockScreen | boolean | 是 | 是否设置应用显示在锁屏之上。true表示显示在锁屏之上;false表示不显示在锁屏之上。 | 6453 6454**错误码:** 6455 6456以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 6457 6458| 错误码ID | 错误信息 | 6459| ------- | ------------------------------ | 6460| 1300002 | This window state is abnormal. | 6461| 1300005 | This window stage is abnormal. | 6462 6463**示例:** 6464 6465```ts 6466import UIAbility from '@ohos.app.ability.UIAbility'; 6467 6468class myAbility extends UIAbility { 6469 onWindowStageCreate(windowStage) { 6470 console.log('onWindowStageCreate'); 6471 try { 6472 windowStage.setShowOnLockScreen(true); 6473 } catch (exception) { 6474 console.error('Failed to show on lockscreen. Cause:' + JSON.stringify(exception)); 6475 }; 6476 } 6477}; 6478``` 6479## TransitionContext<sup>9+</sup> 6480 6481属性转换的上下文信息。 6482 6483### 属性 6484 6485**系统接口:** 此接口为系统接口。 6486 6487**系统能力**:SystemCapability.WindowManager.WindowManager.Core 6488 6489| 名称 | 类型 | 可读 | 可写 | 说明 | 6490| --------------------- | ----------------- | ---- | ---- | ---------------- | 6491| toWindow<sup>9+</sup> | [Window](#window) | 是 | 是 | 动画的目标窗口。 | 6492 6493### completeTransition<sup>9+</sup> 6494 6495completeTransition(isCompleted: boolean): void 6496 6497设置属性转换的最终完成状态。该函数需要在动画函数[animateTo()](../arkui-ts/ts-explicit-animation.md)执行后设置。 6498 6499**系统接口:** 此接口为系统接口。 6500 6501**系统能力**:SystemCapability.WindowManager.WindowManager.Core 6502 6503**参数:** 6504 6505| 参数名 | 类型 | 必填 | 说明 | 6506| ----------- | ------- | ---- | ------------------------------------------------------------ | 6507| isCompleted | boolean | 是 | 窗口属性转换是否完成。true表示完成本次转换;false表示撤销本次转换。 | 6508 6509**示例:** 6510 6511```js 6512let controller = windowClass.getTransitionController(); 6513controller.animationForShown = (context : window.TransitionContext) => { 6514 let toWindow = context.toWindow; 6515 animateTo({ 6516 duration: 1000, // 动画时长 6517 tempo: 0.5, // 播放速率 6518 curve: Curve.EaseInOut, // 动画曲线 6519 delay: 0, // 动画延迟 6520 iterations: 1, // 播放次数 6521 playMode: PlayMode.Normal, // 动画模式 6522 }, () => { 6523 let obj : window.TranslateOptions = { 6524 x : 100.0, 6525 y : 0.0, 6526 z : 0.0 6527 }; 6528 toWindow.translate(obj); 6529 console.info('toWindow translate end'); 6530 } 6531 ); 6532 try { 6533 context.completeTransition(true) 6534 } catch (exception) { 6535 console.info('toWindow translate fail. Cause: ' + JSON.stringify(exception)); 6536 } 6537 console.info('complete transition end'); 6538}; 6539``` 6540 6541## TransitionController<sup>9+</sup> 6542 6543属性转换控制器。 6544 6545### animationForShown<sup>9+</sup> 6546 6547animationForShown(context: TransitionContext): void 6548 6549窗口显示时的自定义动画配置。 6550 6551**系统接口:** 此接口为系统接口。 6552 6553**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6554 6555**参数:** 6556 6557| 参数名 | 类型 | 必填 | 说明 | 6558| ------- | ---------------------------------------- | ---- | -------------------- | 6559| context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | 6560 6561**示例:** 6562 6563```js 6564let controller = windowClass.getTransitionController(); 6565controller.animationForShown = (context : window.TransitionContext) => { 6566 let toWindow = context.toWindow; 6567 animateTo({ 6568 duration: 1000, // 动画时长 6569 tempo: 0.5, // 播放速率 6570 curve: Curve.EaseInOut, // 动画曲线 6571 delay: 0, // 动画延迟 6572 iterations: 1, // 播放次数 6573 playMode: PlayMode.Normal, // 动画模式 6574 onFinish: ()=> { 6575 context.completeTransition(true) 6576 } 6577 }, () => { 6578 let obj : window.TranslateOptions = { 6579 x : 100.0, 6580 y : 0.0, 6581 z : 0.0 6582 }; 6583 toWindow.translate(obj); 6584 console.info('toWindow translate end'); 6585 } 6586 ); 6587 console.info('complete transition end'); 6588}; 6589``` 6590 6591### animationForHidden<sup>9+</sup> 6592 6593animationForHidden(context: TransitionContext): void 6594 6595窗口隐藏时的自定义动画配置。 6596 6597**系统接口:** 此接口为系统接口。 6598 6599**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6600 6601**参数:** 6602 6603| 参数名 | 类型 | 必填 | 说明 | 6604| ------- | ---------------------------------------- | ---- | -------------------- | 6605| context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | 6606 6607**示例:** 6608 6609```js 6610let controller = windowClass.getTransitionController(); 6611controller.animationForHidden = (context : window.TransitionContext) => { 6612 let toWindow = context.toWindow; 6613 animateTo({ 6614 duration: 1000, // 动画时长 6615 tempo: 0.5, // 播放速率 6616 curve: Curve.EaseInOut, // 动画曲线 6617 delay: 0, // 动画延迟 6618 iterations: 1, // 播放次数 6619 playMode: PlayMode.Normal, // 动画模式 6620 onFinish: ()=> { 6621 context.completeTransition(true) 6622 } 6623 }, () => { 6624 let obj : window.TranslateOptions = { 6625 x : 100.0, 6626 y : 0.0, 6627 z : 0.0 6628 }; 6629 toWindow.translate(obj); 6630 console.info('toWindow translate end'); 6631 } 6632 ) 6633 console.info('complete transition end'); 6634}; 6635``` 6636