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```ts 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>10+</sup> | 16 | 表示模态窗口。<br>**模型约束:** 此接口仅可在Stage模型下使用。 | 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 | 表示系统默认区域。一般包括状态栏、导航栏,各设备系统定义可能不同。 | 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.0, 1.0],其取1.0时表示最大亮度值。如果窗口没有设置亮度值,表示亮度跟随系统,此时获取到的亮度值为-1。 | 236| dimBehindValue<sup>(deprecated)</sup> | number | 是 | 是 | 靠后窗口的暗度值。该参数为浮点数,取值范围为[0.0, 1.0],其取1.0表示最暗。<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,该参数应为整数。 | 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,单位为px。 | 296| y | number | 否 | 是 | Y轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | 297| z | number | 否 | 是 | Z轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | 298 299## WindowEventType<sup>10+</sup> 300 301窗口生命周期。 302 303**系统能力**:SystemCapability.WindowManager.WindowManager.Core 304 305| 名称 | 值 | 说明 | 306| ---------- | ------ | ---------- | 307| WINDOW_SHOWN | 1 | 切到前台。 | 308| WINDOW_ACTIVE | 2 | 获焦状态。 | 309| WINDOW_INACTIVE | 3 | 失焦状态。 | 310| WINDOW_HIDDEN | 4 | 切到后台。 | 311 312## window.createWindow<sup>9+</sup> 313 314createWindow(config: Configuration, callback: AsyncCallback<Window>): void 315 316创建子窗口或者系统窗口,使用callback异步回调。 317 318**系统能力:** SystemCapability.WindowManager.WindowManager.Core 319 320**参数:** 321 322| 参数名 | 类型 | 必填 | 说明 | 323| -------- | -------------------------------------- | -- | --------------------------------- | 324| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 325| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的窗口对象。 | 326 327**错误码:** 328 329以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 330 331| 错误码ID | 错误信息 | 332| ------- | -------------------------------- | 333| 1300001 | Repeated operation. | 334| 1300006 | This window context is abnormal. | 335| 1300008 | The operation is on invalid display. | 336| 1300009 | The parent window is invalid. | 337 338**示例:** 339 340```ts 341import { BusinessError } from '@ohos.base'; 342 343let windowClass: window.Window | undefined = undefined; 344let config: window.Configuration = { 345 name: "test", 346 windowType: window.WindowType.TYPE_DIALOG, 347 ctx: this.context 348}; 349try { 350 window.createWindow(config, (err: BusinessError, data) => { 351 const errCode: number = err.code; 352 if (errCode) { 353 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 354 return; 355 } 356 windowClass = data; 357 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 358 windowClass.resize(500, 1000); 359 }); 360} catch (exception) { 361 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 362} 363``` 364 365## window.createWindow<sup>9+</sup> 366 367createWindow(config: Configuration): Promise<Window> 368 369创建子窗口或者系统窗口,使用Promise异步回调。 370 371**系统能力:** SystemCapability.WindowManager.WindowManager.Core 372 373**参数:** 374 375| 参数名 | 类型 | 必填 | 说明 | 376| ------ | -------------------------------- | -- | ------------------ | 377| config | [Configuration](#configuration9) | 是 | 创建窗口时的参数。 | 378 379**返回值:** 380 381| 类型 | 说明 | 382| -------------------------------- | ------------------------------------ | 383| Promise<[Window](#window)> | Promise对象。返回当前创建的窗口对象。 | 384 385**错误码:** 386 387以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 388 389| 错误码ID | 错误信息 | 390| ------- | -------------------------------- | 391| 1300001 | Repeated operation. | 392| 1300006 | This window context is abnormal. | 393| 1300008 | The operation is on invalid display. | 394| 1300009 | The parent window is invalid. | 395 396**示例:** 397 398```ts 399import { BusinessError } from '@ohos.base'; 400 401let windowClass: window.Window | undefined = undefined; 402let config: window.Configuration = { 403 name: "test", 404 windowType: window.WindowType.TYPE_DIALOG, 405 ctx: this.context 406}; 407try { 408 let promise = window.createWindow(config); 409 promise.then((data) => { 410 windowClass = data; 411 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 412 }).catch((err: BusinessError) => { 413 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 414 }); 415} catch (exception) { 416 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 417} 418``` 419 420## window.findWindow<sup>9+</sup> 421 422findWindow(name: string): Window 423 424查找name所对应的窗口。 425 426**系统能力:** SystemCapability.WindowManager.WindowManager.Core 427 428**参数:** 429 430| 参数名 | 类型 | 必填 | 说明 | 431| ------ | ------ | ---- | -------- | 432| name | string | 是 | 窗口id。 | 433 434**返回值:** 435 436| 类型 | 说明 | 437| ----------------- | ------------------- | 438| [Window](#window) | 当前查找的窗口对象。 | 439 440**错误码:** 441 442以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 443 444| 错误码ID | 错误信息 | 445| ------- | -------------------------------- | 446| 1300002 | This window state is abnormal. | 447 448**示例:** 449 450```ts 451let windowClass: window.Window | undefined = undefined; 452try { 453 windowClass = window.findWindow('test'); 454} catch (exception) { 455 console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception)); 456} 457``` 458 459## window.getLastWindow<sup>9+</sup> 460 461getLastWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 462 463获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。 464 465**系统能力:** SystemCapability.WindowManager.WindowManager.Core 466 467**参数:** 468 469| 参数名 | 类型 | 必填 | 说明 | 470| -------- | -------------------------------------- | -- | ---------------------------------------- | 471| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 472| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 473 474**错误码:** 475 476以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 477 478| 错误码ID | 错误信息 | 479| ------- | -------------------------------- | 480| 1300002 | This window state is abnormal. | 481| 1300006 | This window context is abnormal. | 482 483**示例:** 484 485```ts 486import UIAbility from '@ohos.app.ability.UIAbility'; 487import window from '@ohos.window'; 488import { BusinessError } from '@ohos.base'; 489 490export default class EntryAbility extends UIAbility { 491 // ... 492 onWindowStageCreate(windowStage: window.WindowStage) { 493 console.log('onWindowStageCreate'); 494 let windowClass: window.Window | undefined = undefined; 495 try { 496 window.getLastWindow(this.context, (err: BusinessError, data) => { 497 const errCode: number = err.code; 498 if (errCode) { 499 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 500 return; 501 } 502 windowClass = data; 503 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 504 }); 505 } catch (exception) { 506 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 507 } 508 } 509} 510``` 511 512## window.getLastWindow<sup>9+</sup> 513 514getLastWindow(ctx: BaseContext): Promise<Window> 515 516获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用Promise异步回调。 517 518**系统能力:** SystemCapability.WindowManager.WindowManager.Core 519 520**参数:** 521 522| 参数名 | 类型 | 必填 | 说明 | 523| ------ | ----------- | ---- | ------------------------------------------------------------ | 524| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 525 526**返回值:** 527 528| 类型 | 说明 | 529| -------------------------------- | ------------------------------------------- | 530| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 531 532**错误码:** 533 534以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 535 536| 错误码ID | 错误信息 | 537| ------- | -------------------------------- | 538| 1300002 | This window state is abnormal. | 539| 1300006 | This window context is abnormal. | 540 541**示例:** 542 543```ts 544import UIAbility from '@ohos.app.ability.UIAbility'; 545import window from '@ohos.window'; 546import { BusinessError } from '@ohos.base'; 547 548export default class EntryAbility extends UIAbility { 549 // ... 550 onWindowStageCreate(windowStage: window.WindowStage) { 551 console.log('onWindowStageCreate'); 552 let windowClass: window.Window | undefined = undefined; 553 try { 554 let promise = window.getLastWindow(this.context); 555 promise.then((data) => { 556 windowClass = data; 557 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 558 }).catch((err: BusinessError) => { 559 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 560 }); 561 } catch (exception) { 562 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); 563 } 564 } 565} 566``` 567 568## window.minimizeAll<sup>9+</sup> 569minimizeAll(id: number, callback: AsyncCallback<void>): void 570 571最小化某显示设备下的所有窗口。 572 573**系统接口:** 此接口为系统接口。 574 575**系统能力:** SystemCapability.WindowManager.WindowManager.Core 576 577**参数:** 578 579| 参数名 | 类型 | 必填 | 说明 | 580| -------- | ------------------------- | ---- | -------------- | 581| id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号,该参数仅支持整数输入。 | 582| callback | AsyncCallback<void> | 是 | 回调信息。 | 583 584**错误码:** 585 586以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 587 588| 错误码ID | 错误信息 | 589| ------- | -------------------------------------------- | 590| 1300003 | This window manager service works abnormally. | 591 592**示例:** 593 594```ts 595import display from '@ohos.display' 596import { BusinessError } from '@ohos.base'; 597 598let displayClass: display.Display | null = null; 599try { 600 displayClass = display.getDefaultDisplaySync(); 601 602 try { 603 window.minimizeAll(displayClass.id, (err: BusinessError) => { 604 const errCode: number = err.code; 605 if (errCode) { 606 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); 607 return; 608 } 609 console.info('Succeeded in minimizing all windows.'); 610 }); 611 } catch (exception) { 612 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception)); 613 } 614} catch (exception) { 615 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 616} 617``` 618 619## window.minimizeAll<sup>9+</sup> 620minimizeAll(id: number): Promise<void> 621 622最小化某显示设备下的所有窗口。 623 624**系统接口:** 此接口为系统接口。 625 626**系统能力:** SystemCapability.WindowManager.WindowManager.Core 627 628**参数:** 629 630| 参数名 | 类型 | 必填 | 说明 | 631| -------- | ------------------------- | ---- | -------------- | 632| id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号,该参数仅支持整数输入。 | 633 634**返回值:** 635 636| 类型 | 说明 | 637| ------------------- | ------------------------- | 638| Promise<void> | 无返回结果的Promise对象。 | 639 640**错误码:** 641 642以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 643 644| 错误码ID | 错误信息 | 645| ------- | -------------------------------------------- | 646| 1300003 | This window manager service works abnormally. | 647 648**示例:** 649 650```ts 651import display from '@ohos.display' 652import { BusinessError } from '@ohos.base'; 653 654let displayClass: display.Display | null = null; 655try { 656 displayClass = display.getDefaultDisplaySync(); 657 658 try { 659 let promise = window.minimizeAll(displayClass.id); 660 promise.then(() => { 661 console.info('Succeeded in minimizing all windows.'); 662 }).catch((err: BusinessError) => { 663 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(err)); 664 }); 665 } catch (exception) { 666 console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception)); 667 } 668} catch (exception) { 669 console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 670} 671``` 672 673## window.toggleShownStateForAllAppWindows<sup>9+</sup> 674toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void 675 676多窗口快速切换时隐藏或者恢复应用窗口。 677 678**系统接口:** 此接口为系统接口。 679 680**系统能力:** SystemCapability.WindowManager.WindowManager.Core 681 682**参数:** 683 684| 参数名 | 类型 | 必填 | 说明 | 685| -------- | ------------------------- | ---- | -------------- | 686| callback | AsyncCallback<void> | 是 | 回调信息。 | 687 688**错误码:** 689 690以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 691 692| 错误码ID | 错误信息 | 693| ------- | -------------------------------------------- | 694| 1300003 | This window manager service works abnormally. | 695 696**示例:** 697 698```ts 699import { BusinessError } from '@ohos.base'; 700 701window.toggleShownStateForAllAppWindows((err: BusinessError) => { 702 const errCode: number = err.code; 703 if (errCode) { 704 console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); 705 return; 706 } 707 console.info('Succeeded in toggling shown state for all app windows.'); 708}); 709``` 710 711## window.toggleShownStateForAllAppWindows<sup>9+</sup> 712toggleShownStateForAllAppWindows(): Promise<void> 713 714多窗口快速切换时隐藏或者恢复应用窗口。 715 716**系统接口:** 此接口为系统接口。 717 718**系统能力:** SystemCapability.WindowManager.WindowManager.Core 719 720**返回值:** 721 722| 类型 | 说明 | 723| ------------------- | ------------------------- | 724| Promise<void> | 无返回结果的Promise对象。 | 725 726**错误码:** 727 728以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 729 730| 错误码ID | 错误信息 | 731| ------- | -------------------------------------------- | 732| 1300003 | This window manager service works abnormally. | 733 734**示例:** 735 736```ts 737import { BusinessError } from '@ohos.base'; 738 739let promise = window.toggleShownStateForAllAppWindows(); 740promise.then(() => { 741 console.info('Succeeded in toggling shown state for all app windows.'); 742}).catch((err: BusinessError) => { 743 console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err)); 744}); 745``` 746 747## window.setWindowLayoutMode<sup>9+</sup> 748setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void 749 750设置窗口布局模式。 751 752**系统接口:** 此接口为系统接口。 753 754**系统能力:** SystemCapability.WindowManager.WindowManager.Core 755 756**参数:** 757 758| 参数名 | 类型 | 必填 | 说明 | 759| -------- | ------------------------- | ---- | -------------- | 760| mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | 761| callback | AsyncCallback<void> | 是 | 回调信息。 | 762 763**错误码:** 764 765以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 766 767| 错误码ID | 错误信息 | 768| ------- | -------------------------------------------- | 769| 1300003 | This window manager service works abnormally. | 770 771**示例:** 772 773```ts 774import { BusinessError } from '@ohos.base'; 775 776try { 777 window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (err: BusinessError) => { 778 const errCode: number = err.code; 779 if (errCode) { 780 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); 781 return; 782 } 783 console.info('Succeeded in setting window layout mode.'); 784 }); 785} catch (exception) { 786 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception)); 787} 788``` 789 790## window.setWindowLayoutMode<sup>9+</sup> 791setWindowLayoutMode(mode: WindowLayoutMode): Promise<void> 792 793设置窗口布局模式。 794 795**系统接口:** 此接口为系统接口。 796 797**系统能力:** SystemCapability.WindowManager.WindowManager.Core 798 799**参数:** 800 801| 参数名 | 类型 | 必填 | 说明 | 802| -------- | ------------------------- | ---- | -------------- | 803| mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | 804 805**返回值:** 806 807| 类型 | 说明 | 808| ------------------- | ------------------------- | 809| Promise<void> | 无返回结果的Promise对象。 | 810 811**错误码:** 812 813以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 814 815| 错误码ID | 错误信息 | 816| ------- | -------------------------------------------- | 817| 1300003 | This window manager service works abnormally. | 818 819**示例:** 820 821```ts 822import { BusinessError } from '@ohos.base'; 823 824try { 825 let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE); 826 promise.then(() => { 827 console.info('Succeeded in setting window layout mode.'); 828 }).catch((err: BusinessError) => { 829 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(err)); 830 }); 831} catch (exception) { 832 console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception)); 833} 834``` 835 836## window.on('systemBarTintChange')<sup>8+</sup> 837 838on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void 839 840开启状态栏、导航栏属性变化的监听。 841 842**系统接口:** 此接口为系统接口。 843 844**系统能力:** SystemCapability.WindowManager.WindowManager.Core 845 846**参数:** 847 848| 参数名 | 类型 | 必填 | 说明 | 849| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 850| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | 851| callback | Callback<[SystemBarTintState](#systembartintstate8)> | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 | 852 853**示例:** 854 855```ts 856try { 857 window.on('systemBarTintChange', (data) => { 858 console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data)); 859 }); 860} catch (exception) { 861 console.error('Failed to enable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception)); 862} 863``` 864 865## window.off('systemBarTintChange')<sup>8+</sup> 866 867off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void 868 869关闭状态栏、导航栏属性变化的监听。 870 871**系统接口:** 此接口为系统接口。 872 873**系统能力:** SystemCapability.WindowManager.WindowManager.Core 874 875**参数:** 876 877| 参数名 | 类型 | 必填 | 说明 | 878| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 879| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | 880| callback | Callback<[SystemBarTintState](#systembartintstate8)> | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有状态栏、导航栏属性变化的监听。 | 881 882**示例:** 883 884```ts 885try { 886 window.off('systemBarTintChange'); 887} catch (exception) { 888 console.error('Failed to disable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception)); 889} 890``` 891 892## window.on('gestureNavigationEnabledChange')<sup>10+</sup> 893 894on(type: 'gestureNavigationEnabledChange', callback: Callback<boolean>): void 895 896添加手势导航启用状态变化的监听。 897 898**系统接口:** 此接口为系统接口。 899 900**系统能力:** SystemCapability.WindowManager.WindowManager.Core 901 902**参数:** 903 904| 参数名 | 类型 | 必填 | 说明 | 905| -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | 906| type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 | 907| callback | Callback<boolean> | 是 | 回调函数。返回当前手势导航的启用状态。true表示手势导航状态变化为启用;false表示手势导航状态变化为禁用。 | 908 909**错误码:** 910 911以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 912 913| 错误码ID | 错误信息 | 914| ------- | -------------------------------------------- | 915| 1300002 | This window state is abnormal. | 916| 1300003 | This window manager service works abnormally. | 917 918**示例:** 919 920```ts 921try { 922 window.on('gestureNavigationEnabledChange', (data) => { 923 console.info('Succeeded in enabling the listener for gesture navigation status changes. Data: ' + JSON.stringify(data)); 924 }); 925} catch (exception) { 926 console.error('Failed to enable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception)); 927} 928``` 929 930## window.off('gestureNavigationEnabledChange')<sup>10+</sup> 931 932off(type: 'gestureNavigationEnabledChange', callback?: Callback<boolean>): void 933 934移除手势导航启用状态变化的监听。 935 936**系统接口:** 此接口为系统接口。 937 938**系统能力:** SystemCapability.WindowManager.WindowManager.Core 939 940**参数:** 941 942| 参数名 | 类型 | 必填 | 说明 | 943| -------- | ----------------------- | -- | ------------------------------------------------------------ | 944| type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 | 945| callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有手势导航启用状态变化的监听。 | 946 947**错误码:** 948 949以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 950 951| 错误码ID | 错误信息 | 952| ------- | -------------------------------------------- | 953| 1300002 | This window state is abnormal. | 954| 1300003 | This window manager service works abnormally. | 955 956**示例:** 957 958```ts 959try { 960 window.off('gestureNavigationEnabledChange'); 961} catch (exception) { 962 console.error('Failed to disable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception)); 963} 964``` 965 966## window.on('waterMarkFlagChange')<sup>10+</sup> 967 968on(type: 'waterMarkFlagChange', callback: Callback<boolean>): void 969 970添加水印启用状态变化的监听。 971 972**系统接口:** 此接口为系统接口。 973 974**系统能力:** SystemCapability.WindowManager.WindowManager.Core 975 976**参数:** 977 978| 参数名 | 类型 | 必填 | 说明 | 979| -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | 980| type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 | 981| callback | Callback<boolean> | 是 | 回调函数。返回当前水印的启用状态。true表示当前已启用水印;false表示当前未启用水印。 | 982 983**错误码:** 984 985以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 986 987| 错误码ID | 错误信息 | 988| ------- | -------------------------------------------- | 989| 1300003 | This window manager service works abnormally. | 990 991**示例:** 992 993```ts 994try { 995 window.on('waterMarkFlagChange', (data) => { 996 console.info('Succeeded in enabling the listener for watermark flag changes. Data: ' + JSON.stringify(data)); 997 }); 998} catch (exception) { 999 console.error('Failed to enable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception)); 1000} 1001``` 1002 1003## window.off('waterMarkFlagChange')<sup>10+</sup> 1004 1005off(type: 'waterMarkFlagChange', callback?: Callback<boolean>): void 1006 1007移除水印启用状态变化的监听。 1008 1009**系统接口:** 此接口为系统接口。 1010 1011**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1012 1013**参数:** 1014 1015| 参数名 | 类型 | 必填 | 说明 | 1016| -------- | ----------------------- | -- | ------------------------------------------------------------ | 1017| type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 | 1018| callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有水印启用状态变化的监听。 | 1019 1020**错误码:** 1021 1022以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1023 1024| 错误码ID | 错误信息 | 1025| ------- | -------------------------------------------- | 1026| 1300003 | This window manager service works abnormally. | 1027 1028**示例:** 1029 1030```ts 1031try { 1032 window.off('waterMarkFlagChange'); 1033} catch (exception) { 1034 console.error('Failed to disable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception)); 1035} 1036``` 1037 1038## window.setGestureNavigationEnabled<sup>10+</sup> 1039setGestureNavigationEnabled(enable: boolean, callback: AsyncCallback<void>): void 1040 1041设置手势导航启用状态。使用callback异步回调。 1042 1043**系统接口:** 此接口为系统接口。 1044 1045**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1046 1047**参数:** 1048 1049| 参数名 | 类型 | 必填 | 说明 | 1050| -------- | ------------------------- | ---- | -------------- | 1051| enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 | 1052| callback | AsyncCallback<void> | 是 | 回调信息。 | 1053 1054**错误码:** 1055 1056以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1057 1058| 错误码ID | 错误信息 | 1059| ------- | --------------------------------------------- | 1060| 1300002 | This window state is abnormal. | 1061| 1300003 | This window manager service works abnormally. | 1062 1063**示例:** 1064 1065```ts 1066import { BusinessError } from '@ohos.base'; 1067 1068try { 1069 window.setGestureNavigationEnabled(true, (err: BusinessError) => { 1070 const errCode: number = err.code; 1071 if (errCode) { 1072 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err)); 1073 return; 1074 } 1075 console.info('Succeeded in setting gesture navigation enabled.'); 1076 }); 1077} catch (exception) { 1078 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception)); 1079} 1080``` 1081 1082## window.setGestureNavigationEnabled<sup>10+</sup> 1083setGestureNavigationEnabled(enable: boolean): Promise<void> 1084 1085设置手势导航启用状态。使用Promise异步回调。 1086 1087**系统接口:** 此接口为系统接口。 1088 1089**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1090 1091**参数:** 1092 1093| 参数名 | 类型 | 必填 | 说明 | 1094| ------ | ------- | ---- | -------------------- | 1095| enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 | 1096 1097**返回值:** 1098 1099| 类型 | 说明 | 1100| ------------------- | ------------------------- | 1101| Promise<void> | 无返回结果的Promise对象。 | 1102 1103**错误码:** 1104 1105以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1106 1107| 错误码ID | 错误信息 | 1108| ------- | -------------------------------------------- | 1109| 1300002 | This window state is abnormal. | 1110| 1300003 | This window manager service works abnormally. | 1111 1112**示例:** 1113 1114```ts 1115import { BusinessError } from '@ohos.base'; 1116 1117try { 1118 let promise = window.setGestureNavigationEnabled(true); 1119 promise.then(() => { 1120 console.info('Succeeded in setting gesture navigation enabled.'); 1121 }).catch((err: BusinessError) => { 1122 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err)); 1123 }); 1124} catch (exception) { 1125 console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception)); 1126} 1127``` 1128 1129## window.setWaterMarkImage<sup>10+</sup> 1130setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean, callback: AsyncCallback<void>): void 1131 1132设置水印图片显示状态。使用callback异步回调。 1133 1134**系统接口:** 此接口为系统接口。 1135 1136**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1137 1138**参数:** 1139 1140| 参数名 | 类型 | 必填 | 说明 | 1141| -------- | ------------------------- | ---- | -------------- | 1142| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | 是 | 水印图片。 | 1143| enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 | 1144| callback | AsyncCallback<void> | 是 | 回调信息。 | 1145 1146**错误码:** 1147 1148以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1149 1150| 错误码ID | 错误信息 | 1151| ------- | --------------------------------------------- | 1152| 1300003 | This window manager service works abnormally. | 1153 1154**示例:** 1155 1156```ts 1157import image from '@ohos.multimedia.image'; 1158import { BusinessError } from '@ohos.base'; 1159 1160let enable: boolean = true; 1161let color: ArrayBuffer = new ArrayBuffer(0); 1162let initializationOptions: image.InitializationOptions = { 1163 size: { 1164 height: 100, 1165 width: 100 1166 } 1167}; 1168image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { 1169 console.info('Succeeded in creating pixelmap.'); 1170 try { 1171 window.setWaterMarkImage(pixelMap, enable, (err: BusinessError) => { 1172 const errCode: number = err.code; 1173 if (errCode) { 1174 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(err)); 1175 return; 1176 } 1177 console.info('Succeeded in showing watermark image.'); 1178 }); 1179 } catch (exception) { 1180 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception)); 1181 } 1182}).catch((err: BusinessError) => { 1183 console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err)); 1184}); 1185``` 1186 1187## window.setWaterMarkImage<sup>10+</sup> 1188setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean): Promise<void> 1189 1190设置水印图片显示状态。使用Promise异步回调。 1191 1192**系统接口:** 此接口为系统接口。 1193 1194**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1195 1196**参数:** 1197 1198| 参数名 | 类型 | 必填 | 说明 | 1199| ------ | --------------------------- | ---- | -------------------- | 1200| pixelMap | [image.PixelMap](js-apis-image.md#pixelmap7) | 是 | 水印图片。 | 1201| enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 | 1202 1203**返回值:** 1204 1205| 类型 | 说明 | 1206| ------------------- | ------------------------- | 1207| Promise<void> | 无返回结果的Promise对象。 | 1208 1209**错误码:** 1210 1211以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1212 1213| 错误码ID | 错误信息 | 1214| ------- | -------------------------------------------- | 1215| 1300003 | This window manager service works abnormally. | 1216 1217**示例:** 1218 1219```ts 1220import image from '@ohos.multimedia.image'; 1221import { BusinessError } from '@ohos.base'; 1222 1223let enable: boolean = true; 1224let color: ArrayBuffer = new ArrayBuffer(0); 1225let initializationOptions: image.InitializationOptions = { 1226 size: { 1227 height: 100, 1228 width: 100 1229 } 1230}; 1231image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { 1232 console.info('Succeeded in creating pixelmap.'); 1233 try { 1234 let promise = window.setWaterMarkImage(pixelMap, enable); 1235 promise.then(() => { 1236 console.info('Succeeded in showing watermark image.'); 1237 }).catch((err: BusinessError) => { 1238 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(err)); 1239 }); 1240 } catch (exception) { 1241 console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception)); 1242 } 1243}).catch((err: BusinessError) => { 1244 console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err)); 1245}); 1246``` 1247 1248## window.create<sup>(deprecated)</sup> 1249 1250create(id: string, type: WindowType, callback: AsyncCallback<Window>): void 1251 1252创建子窗口,使用callback异步回调。 1253 1254> **说明:** 1255> 1256> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 1257 1258**模型约束:** 此接口仅可在FA模型下使用。 1259 1260**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1261 1262**参数:** 1263 1264| 参数名 | 类型 | 必填 | 说明 | 1265| -------- | -------------------------------------- | ---- | ------------------------------------ | 1266| id | string | 是 | 窗口id。 | 1267| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1268| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 1269 1270**示例:** 1271 1272```ts 1273import { BusinessError } from '@ohos.base'; 1274 1275let windowClass: window.Window | undefined = undefined; 1276window.create('test', window.WindowType.TYPE_APP, (err: BusinessError, data) => { 1277 const errCode: number = err.code; 1278 if (errCode) { 1279 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 1280 return; 1281 } 1282 windowClass = data; 1283 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1284}); 1285``` 1286 1287## window.create<sup>(deprecated)</sup> 1288 1289create(id: string, type: WindowType): Promise<Window> 1290 1291创建子窗口,使用Promise异步回调。 1292 1293> **说明:** 1294> 1295> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 1296 1297**模型约束:** 此接口仅可在FA模型下使用。 1298 1299**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1300 1301**参数:** 1302 1303| 参数名 | 类型 | 必填 | 说明 | 1304| ------ | ------------------------- | ---- | ---------- | 1305| id | string | 是 | 窗口id。 | 1306| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1307 1308**返回值:** 1309 1310| 类型 | 说明 | 1311| -------------------------------- | --------------------------------------- | 1312| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 1313 1314**示例:** 1315 1316```ts 1317import { BusinessError } from '@ohos.base'; 1318 1319let windowClass: window.Window | undefined = undefined; 1320let promise = window.create('test', window.WindowType.TYPE_APP); 1321promise.then((data) => { 1322 windowClass = data; 1323 console.info('Succeeded in creating the subWindow. Data: ' + JSON.stringify(data)); 1324}).catch((err: BusinessError) => { 1325 console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err)); 1326}); 1327``` 1328 1329## window.create<sup>(deprecated)</sup> 1330 1331create(ctx: BaseContext, id: string, type: WindowType, callback: AsyncCallback<Window>): void 1332 1333创建系统窗口,使用callback异步回调。 1334 1335> **说明:** 1336> 1337> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9)。 1338 1339**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1340 1341**参数:** 1342 1343| 参数名 | 类型 | 必填 | 说明 | 1344| -------- | ------------------------------------------------------- | ---- | ------------------------------------ | 1345| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1346| id | string | 是 | 窗口id。 | 1347| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1348| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前创建的子窗口对象。 | 1349 1350**示例:** 1351 1352```ts 1353import { BusinessError } from '@ohos.base'; 1354 1355let windowClass: window.Window | undefined = undefined; 1356window.create('test', window.WindowType.TYPE_SYSTEM_ALERT, (err: BusinessError, data) => { 1357 const errCode: number = err.code; 1358 if (errCode) { 1359 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 1360 return; 1361 } 1362 windowClass = data; 1363 console.info('Succeeded in creating the window. Data: ' + JSON.stringify(data)); 1364 windowClass.resetSize(500, 1000); 1365}); 1366``` 1367 1368## window.create<sup>(deprecated)</sup> 1369 1370create(ctx: BaseContext, id: string, type: WindowType): Promise<Window> 1371 1372创建系统窗口,使用Promise异步回调。 1373 1374> **说明:** 1375> 1376> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[createWindow()](#windowcreatewindow9-1)。 1377 1378**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1379 1380**参数:** 1381 1382| 参数名 | 类型 | 必填 | 说明 | 1383| ------ | ------------------------- | ---- | ------------------------------------------------------------ | 1384| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1385| id | string | 是 | 窗口id。 | 1386| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 1387 1388**返回值:** 1389 1390| 类型 | 说明 | 1391| -------------------------------- | --------------------------------------- | 1392| Promise<[Window](#window)> | Promise对象。返回当前创建的子窗口对象。 | 1393 1394**示例:** 1395 1396```ts 1397import { BusinessError } from '@ohos.base'; 1398 1399let windowClass: window.Window | undefined = undefined; 1400let promise = window.create('test', window.WindowType.TYPE_SYSTEM_ALERT); 1401promise.then((data) => { 1402 windowClass = data; 1403 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 1404}).catch((err: BusinessError) => { 1405 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 1406}); 1407``` 1408 1409## window.find<sup>(deprecated)</sup> 1410 1411find(id: string, callback: AsyncCallback<Window>): void 1412 1413查找id所对应的窗口,使用callback异步回调。 1414 1415> **说明:** 1416> 1417> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1418 1419**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1420 1421**参数:** 1422 1423| 参数名 | 类型 | 必填 | 说明 | 1424| -------- | -------------------------------------- | ---- | ------------------------------------ | 1425| id | string | 是 | 窗口id。 | 1426| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前查找到的窗口对象。 | 1427 1428**示例:** 1429 1430```ts 1431import { BusinessError } from '@ohos.base'; 1432 1433let windowClass: window.Window | undefined = undefined; 1434window.find('test', (err: BusinessError, data) => { 1435 const errCode: number = err.code; 1436 if (errCode) { 1437 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 1438 return; 1439 } 1440 windowClass = data; 1441 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1442}); 1443``` 1444 1445## window.find<sup>(deprecated)</sup> 1446 1447find(id: string): Promise<Window> 1448 1449查找id所对应的窗口,使用Promise异步回调。 1450 1451> **说明:** 1452> 1453> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[findWindow()](#windowfindwindow9)。 1454 1455**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1456 1457**参数:** 1458 1459| 参数名 | 类型 | 必填 | 说明 | 1460| ------ | ------ | ---- | -------- | 1461| id | string | 是 | 窗口id。 | 1462 1463**返回值:** 1464 1465| 类型 | 说明 | 1466| -------------------------------- | ------------------------------------- | 1467| Promise<[Window](#window)> | Promise对象。返回当前查找的窗口对象。 | 1468 1469**示例:** 1470 1471```ts 1472import { BusinessError } from '@ohos.base'; 1473 1474let windowClass: window.Window | undefined = undefined; 1475let promise = window.find('test'); 1476promise.then((data) => { 1477 windowClass = data; 1478 console.info('Succeeded in finding the window. Data: ' + JSON.stringify(data)); 1479}).catch((err: BusinessError) => { 1480 console.error('Failed to find the Window. Cause: ' + JSON.stringify(err)); 1481}); 1482``` 1483 1484## window.getTopWindow<sup>(deprecated)</sup> 1485 1486getTopWindow(callback: AsyncCallback<Window>): void 1487 1488获取当前应用内最后显示的窗口,使用callback异步回调。 1489 1490> **说明:** 1491> 1492> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1493 1494**模型约束:** 此接口仅可在FA模型下使用。 1495 1496**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1497 1498**参数:** 1499 1500| 参数名 | 类型 | 必填 | 说明 | 1501| -------- | -------------------------------------- | ---- | -------------------------------------------- | 1502| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1503 1504**示例:** 1505 1506```ts 1507import { BusinessError } from '@ohos.base'; 1508 1509let windowClass: window.Window | undefined = undefined; 1510window.getTopWindow((err: BusinessError, data) => { 1511 const errCode: number = err.code; 1512 if (errCode) { 1513 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1514 return; 1515 } 1516 windowClass = data; 1517 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1518}); 1519``` 1520 1521## window.getTopWindow<sup>(deprecated)</sup> 1522 1523getTopWindow(): Promise<Window> 1524 1525获取当前应用内最后显示的窗口,使用Promise异步回调。 1526 1527> **说明:** 1528> 1529> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1530 1531**模型约束:** 此接口仅可在FA模型下使用。 1532 1533**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1534 1535**返回值:** 1536 1537| 类型 | 说明 | 1538| -------------------------------- | ----------------------------------------------- | 1539| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1540 1541**示例:** 1542 1543```ts 1544import { BusinessError } from '@ohos.base'; 1545 1546let windowClass: window.Window | undefined = undefined; 1547let promise = window.getTopWindow(); 1548promise.then((data)=> { 1549 windowClass = data; 1550 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1551}).catch((err: BusinessError)=>{ 1552 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1553}); 1554``` 1555 1556## window.getTopWindow<sup>(deprecated)</sup> 1557 1558getTopWindow(ctx: BaseContext, callback: AsyncCallback<Window>): void 1559 1560获取当前应用内最后显示的窗口,使用callback异步回调。 1561 1562> **说明:** 1563> 1564> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9)。 1565 1566**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1567 1568**参数:** 1569 1570| 参数名 | 类型 | 必填 | 说明 | 1571| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 1572| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1573| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 | 1574 1575**示例:** 1576 1577```ts 1578import { BusinessError } from '@ohos.base'; 1579 1580export default class EntryAbility extends UIAbility { 1581 onWindowStageCreate(windowStage:window.WindowStage){ 1582 console.info('onWindowStageCreate'); 1583 let windowClass: window.Window | undefined = undefined; 1584 try { 1585 window.getTopWindow(this.context, (err: BusinessError, data) => { 1586 const errCode: number = err.code; 1587 if(errCode){ 1588 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err)); 1589 return ; 1590 } 1591 windowClass = data; 1592 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1593 }); 1594 } catch(error){ 1595 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 1596 } 1597 } 1598} 1599``` 1600 1601## window.getTopWindow<sup>(deprecated)</sup> 1602 1603getTopWindow(ctx: BaseContext): Promise<Window> 1604 1605获取当前应用内最后显示的窗口,使用Promise异步回调。 1606 1607> **说明:** 1608> 1609> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getLastWindow()](#windowgetlastwindow9-1)。 1610 1611**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1612 1613**参数:** 1614 1615| 参数名 | 类型 | 必填 | 说明 | 1616| ------ | ----------- | ---- | ------------------------------------------------------------ | 1617| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | 是 | 当前应用上下文信息。 | 1618 1619**返回值:** 1620 1621| 类型 | 说明 | 1622| -------------------------------- | ----------------------------------------------- | 1623| Promise<[Window](#window)> | Promise对象。返回当前应用内最后显示的窗口对象。 | 1624 1625**示例:** 1626 1627```ts 1628import { BusinessError } from '@ohos.base'; 1629 1630export default class EntryAbility extends UIAbility { 1631 onWindowStageCreate(windowStage:window.WindowStage) { 1632 console.info('onWindowStageCreate'); 1633 let windowClass: window.Window | undefined = undefined; 1634 let promise = window.getTopWindow(this.context); 1635 promise.then((data) => { 1636 windowClass = data; 1637 console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); 1638 }).catch((error: BusinessError) => { 1639 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 1640 }); 1641 } 1642} 1643``` 1644 1645## Window 1646 1647当前窗口实例,窗口管理器管理的基本单元。 1648 1649下列API示例中都需先使用[getLastWindow()](#windowgetlastwindow9)、[createWindow()](#windowcreatewindow9)、[findWindow()](#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。 1650 1651### hide<sup>7+</sup> 1652 1653hide (callback: AsyncCallback<void>): void 1654 1655隐藏当前窗口,使用callback异步回调。 1656 1657**系统接口:** 此接口为系统接口。 1658 1659**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1660 1661**参数:** 1662 1663| 参数名 | 类型 | 必填 | 说明 | 1664| -------- | ------------------------- | ---- | ---------- | 1665| callback | AsyncCallback<void> | 是 | 回调函数。 | 1666 1667**错误码:** 1668 1669以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1670 1671| 错误码ID | 错误信息 | 1672| ------- | ------------------------------ | 1673| 1300002 | This window state is abnormal. | 1674 1675**示例:** 1676 1677```ts 1678import { BusinessError } from '@ohos.base'; 1679 1680windowClass.hide((err: BusinessError) => { 1681 const errCode: number = err.code; 1682 if (errCode) { 1683 console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); 1684 return; 1685 } 1686 console.info('Succeeded in hiding the window.'); 1687}); 1688``` 1689 1690### hide<sup>7+</sup> 1691 1692hide(): Promise<void> 1693 1694隐藏当前窗口,使用Promise异步回调。 1695 1696**系统接口:** 此接口为系统接口。 1697 1698**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1699 1700**返回值:** 1701 1702| 类型 | 说明 | 1703| ------------------- | ------------------------- | 1704| Promise<void> | 无返回结果的Promise对象。 | 1705 1706**错误码:** 1707 1708以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1709 1710| 错误码ID | 错误信息 | 1711| ------- | ------------------------------ | 1712| 1300002 | This window state is abnormal. | 1713 1714**示例:** 1715 1716```ts 1717import { BusinessError } from '@ohos.base'; 1718 1719let promise = windowClass.hide(); 1720promise.then(() => { 1721 console.info('Succeeded in hiding the window.'); 1722}).catch((err: BusinessError) => { 1723 console.error('Failed to hide the window. Cause: ' + JSON.stringify(err)); 1724}); 1725``` 1726 1727### hideWithAnimation<sup>9+</sup> 1728 1729hideWithAnimation(callback: AsyncCallback<void>): void 1730 1731隐藏当前窗口,过程中播放动画,使用callback异步回调。 1732 1733**系统接口:** 此接口为系统接口。 1734 1735**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1736 1737**参数:** 1738 1739| 参数名 | 类型 | 必填 | 说明 | 1740| -------- | ------------------------- | ---- | ---------- | 1741| callback | AsyncCallback<void> | 是 | 回调函数。 | 1742 1743**错误码:** 1744 1745以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1746 1747| 错误码ID | 错误信息 | 1748| ------- | -------------------------------------------- | 1749| 1300002 | This window state is abnormal. | 1750| 1300003 | This window manager service works abnormally. | 1751| 1300004 | Unauthorized operation. | 1752 1753**示例:** 1754 1755```ts 1756import { BusinessError } from '@ohos.base'; 1757 1758windowClass.hideWithAnimation((err: BusinessError) => { 1759 const errCode: number = err.code; 1760 if (errCode) { 1761 console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 1762 return; 1763 } 1764 console.info('Succeeded in hiding the window with animation.'); 1765}); 1766``` 1767 1768### hideWithAnimation<sup>9+</sup> 1769 1770hideWithAnimation(): Promise<void> 1771 1772隐藏当前窗口,过程中播放动画,使用Promise异步回调。 1773 1774**系统接口:** 此接口为系统接口。 1775 1776**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1777 1778**返回值:** 1779 1780| 类型 | 说明 | 1781| ------------------- | ------------------------- | 1782| Promise<void> | 无返回结果的Promise对象。 | 1783 1784**错误码:** 1785 1786以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1787 1788| 错误码ID | 错误信息 | 1789| ------- | -------------------------------------------- | 1790| 1300002 | This window state is abnormal. | 1791| 1300003 | This window manager service works abnormally. | 1792| 1300004 | Unauthorized operation. | 1793 1794**示例:** 1795 1796```ts 1797import { BusinessError } from '@ohos.base'; 1798 1799let promise = windowClass.hideWithAnimation(); 1800promise.then(() => { 1801 console.info('Succeeded in hiding the window with animation.'); 1802}).catch((err: BusinessError) => { 1803 console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err)); 1804}); 1805``` 1806 1807### showWindow<sup>9+</sup> 1808 1809showWindow(callback: AsyncCallback<void>): void 1810 1811显示当前窗口,使用callback异步回调。 1812 1813**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1814 1815**参数:** 1816 1817| 参数名 | 类型 | 必填 | 说明 | 1818| -------- | ------------------------- | -- | --------- | 1819| callback | AsyncCallback<void> | 是 | 回调函数。 | 1820 1821**错误码:** 1822 1823以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1824 1825| 错误码ID | 错误信息 | 1826| ------- | ------------------------------ | 1827| 1300002 | This window state is abnormal. | 1828 1829**示例:** 1830 1831```ts 1832import { BusinessError } from '@ohos.base'; 1833 1834windowClass.showWindow((err: BusinessError) => { 1835 const errCode: number = err.code; 1836 if (errCode) { 1837 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1838 return; 1839 } 1840 console.info('Succeeded in showing the window.'); 1841}); 1842``` 1843 1844### showWindow<sup>9+</sup> 1845 1846showWindow(): Promise<void> 1847 1848显示当前窗口,使用Promise异步回调。 1849 1850**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1851 1852**返回值:** 1853 1854| 类型 | 说明 | 1855| ------------------- | ----------------------- | 1856| Promise<void> | 无返回结果的Promise对象。 | 1857 1858**错误码:** 1859 1860以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1861 1862| 错误码ID | 错误信息 | 1863| ------- | ------------------------------ | 1864| 1300002 | This window state is abnormal. | 1865 1866**示例:** 1867 1868```ts 1869import { BusinessError } from '@ohos.base'; 1870 1871let promise = windowClass.showWindow(); 1872promise.then(() => { 1873 console.info('Succeeded in showing the window.'); 1874}).catch((err: BusinessError) => { 1875 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 1876}); 1877``` 1878 1879### showWithAnimation<sup>9+</sup> 1880 1881showWithAnimation(callback: AsyncCallback<void>): void 1882 1883显示当前窗口,过程中播放动画,使用callback异步回调。 1884 1885**系统接口:** 此接口为系统接口。 1886 1887**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1888 1889**参数:** 1890 1891| 参数名 | 类型 | 必填 | 说明 | 1892| -------- | ------------------------- | ---- | ---------- | 1893| callback | AsyncCallback<void> | 是 | 回调函数。 | 1894 1895**错误码:** 1896 1897以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1898 1899| 错误码ID | 错误信息 | 1900| ------- | -------------------------------------------- | 1901| 1300002 | This window state is abnormal. | 1902| 1300003 | This window manager service works abnormally. | 1903| 1300004 | Unauthorized operation. | 1904 1905**示例:** 1906 1907```ts 1908import { BusinessError } from '@ohos.base'; 1909 1910windowClass.showWithAnimation((err: BusinessError) => { 1911 const errCode: number = err.code; 1912 if (errCode) { 1913 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 1914 return; 1915 } 1916 console.info('Succeeded in showing the window with animation.'); 1917}); 1918``` 1919 1920### showWithAnimation<sup>9+</sup> 1921 1922showWithAnimation(): Promise<void> 1923 1924显示当前窗口,过程中播放动画,使用Promise异步回调。 1925 1926**系统接口:** 此接口为系统接口。 1927 1928**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1929 1930**返回值:** 1931 1932| 类型 | 说明 | 1933| ------------------- | ------------------------- | 1934| Promise<void> | 无返回结果的Promise对象。 | 1935 1936**错误码:** 1937 1938以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1939 1940| 错误码ID | 错误信息 | 1941| ------- | -------------------------------------------- | 1942| 1300002 | This window state is abnormal. | 1943| 1300003 | This window manager service works abnormally. | 1944| 1300004 | Unauthorized operation. | 1945 1946**示例:** 1947 1948```ts 1949import { BusinessError } from '@ohos.base'; 1950 1951let promise = windowClass.showWithAnimation(); 1952promise.then(() => { 1953 console.info('Succeeded in showing the window with animation.'); 1954}).catch((err: BusinessError) => { 1955 console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err)); 1956}); 1957``` 1958 1959### destroyWindow<sup>9+</sup> 1960 1961destroyWindow(callback: AsyncCallback<void>): void 1962 1963销毁当前窗口,使用callback异步回调。 1964 1965**系统能力:** SystemCapability.WindowManager.WindowManager.Core 1966 1967**参数:** 1968 1969| 参数名 | 类型 | 必填 | 说明 | 1970| -------- | ------------------------- | -- | --------- | 1971| callback | AsyncCallback<void> | 是 | 回调函数。 | 1972 1973**错误码:** 1974 1975以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 1976 1977| 错误码ID | 错误信息 | 1978| ------- | -------------------------------------------- | 1979| 1300002 | This window state is abnormal. | 1980| 1300003 | This window manager service works abnormally. | 1981 1982**示例:** 1983 1984```ts 1985import { BusinessError } from '@ohos.base'; 1986 1987windowClass.destroyWindow((err) => { 1988 const errCode: number = err.code; 1989 if (errCode) { 1990 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 1991 return; 1992 } 1993 console.info('Succeeded in destroying the window.'); 1994}); 1995``` 1996 1997### destroyWindow<sup>9+</sup> 1998 1999destroyWindow(): Promise<void> 2000 2001销毁当前窗口,使用Promise异步回调。 2002 2003**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2004 2005**返回值:** 2006 2007| 类型 | 说明 | 2008| ------------------- | ------------------------ | 2009| Promise<void> | 无返回结果的Promise对象。 | 2010 2011**错误码:** 2012 2013以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2014 2015| 错误码ID | 错误信息 | 2016| ------- | -------------------------------------------- | 2017| 1300002 | This window state is abnormal. | 2018| 1300003 | This window manager service works abnormally. | 2019 2020**示例:** 2021 2022```ts 2023import { BusinessError } from '@ohos.base'; 2024 2025let promise = windowClass.destroyWindow(); 2026promise.then(() => { 2027 console.info('Succeeded in destroying the window.'); 2028}).catch((err: BusinessError) => { 2029 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 2030}); 2031``` 2032 2033### moveWindowTo<sup>9+</sup> 2034 2035moveWindowTo(x: number, y: number, callback: AsyncCallback<void>): void 2036 2037移动窗口位置,使用callback异步回调。 2038 2039全屏模式窗口不支持该操作。 2040 2041**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2042 2043**参数:** 2044 2045| 参数名 | 类型 | 必填 | 说明 | 2046| -------- | ------------------------- | -- | --------------------------------------------- | 2047| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。 | 2048| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。 | 2049| callback | AsyncCallback<void> | 是 | 回调函数。 | 2050 2051**错误码:** 2052 2053以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2054 2055| 错误码ID | 错误信息 | 2056| ------- | -------------------------------------------- | 2057| 1300002 | This window state is abnormal. | 2058| 1300003 | This window manager service works abnormally. | 2059 2060**示例:** 2061 2062```ts 2063import { BusinessError } from '@ohos.base'; 2064 2065try { 2066 windowClass.moveWindowTo(300, 300, (err: BusinessError) => { 2067 const errCode: number = err.code; 2068 if (errCode) { 2069 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 2070 return; 2071 } 2072 console.info('Succeeded in moving the window.'); 2073 }); 2074} catch (exception) { 2075 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 2076} 2077``` 2078 2079### moveWindowTo<sup>9+</sup> 2080 2081moveWindowTo(x: number, y: number): Promise<void> 2082 2083移动窗口位置,使用Promise异步回调。 2084 2085全屏模式窗口不支持该操作。 2086 2087**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2088 2089**参数:** 2090 2091| 参数名 | 类型 | 必填 | 说明 | 2092| -- | ----- | -- | --------------------------------------------- | 2093| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。 | 2094| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。 | 2095 2096**返回值:** 2097 2098| 类型 | 说明 | 2099| ------------------- | ------------------------ | 2100| Promise<void> | 无返回结果的Promise对象。 | 2101 2102**错误码:** 2103 2104以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2105 2106| 错误码ID | 错误信息 | 2107| ------- | -------------------------------------------- | 2108| 1300002 | This window state is abnormal. | 2109| 1300003 | This window manager service works abnormally. | 2110 2111**示例:** 2112 2113```ts 2114import { BusinessError } from '@ohos.base'; 2115 2116try { 2117 let promise = windowClass.moveWindowTo(300, 300); 2118 promise.then(() => { 2119 console.info('Succeeded in moving the window.'); 2120 }).catch((err: BusinessError) => { 2121 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 2122 }); 2123} catch (exception) { 2124 console.error('Failed to move the window. Cause:' + JSON.stringify(exception)); 2125} 2126``` 2127 2128### resize<sup>9+</sup> 2129 2130resize(width: number, height: number, callback: AsyncCallback<void>): void 2131 2132改变当前窗口大小,使用callback异步回调。 2133 2134应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 2135应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。 2136 2137系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 2138 2139设置的宽度与高度受到此约束限制,规则: 2140若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 2141若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 2142 2143全屏模式窗口不支持该操作。 2144 2145**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2146 2147**参数:** 2148 2149| 参数名 | 类型 | 必填 | 说明 | 2150| -------- | ------------------------- | -- | ------------------------ | 2151| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入。 | 2152| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入。 | 2153| callback | AsyncCallback<void> | 是 | 回调函数。 | 2154 2155**错误码:** 2156 2157以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2158 2159| 错误码ID | 错误信息 | 2160| ------- | -------------------------------------------- | 2161| 1300002 | This window state is abnormal. | 2162| 1300003 | This window manager service works abnormally. | 2163 2164**示例:** 2165 2166```ts 2167import { BusinessError } from '@ohos.base'; 2168 2169try { 2170 windowClass.resize(500, 1000, (err: BusinessError) => { 2171 const errCode: number = err.code; 2172 if (errCode) { 2173 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 2174 return; 2175 } 2176 console.info('Succeeded in changing the window size.'); 2177 }); 2178} catch (exception) { 2179 console.error('Failed to change the window size. Cause:' + JSON.stringify(exception)); 2180} 2181``` 2182 2183### resize<sup>9+</sup> 2184 2185resize(width: number, height: number): Promise<void> 2186 2187改变当前窗口大小,使用Promise异步回调。 2188 2189应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 2190应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。 2191 2192系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 2193 2194设置的宽度与高度受到此约束限制,规则: 2195若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 2196若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 2197 2198全屏模式窗口不支持该操作。 2199 2200**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2201 2202**参数:** 2203 2204| 参数名 | 类型 | 必填 | 说明 | 2205| ------ | ------ | -- | ------------------------ | 2206| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入。 | 2207| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入。 | 2208 2209**返回值:** 2210 2211| 类型 | 说明 | 2212| ------------------- | ------------------------ | 2213| Promise<void> | 无返回结果的Promise对象。 | 2214 2215**错误码:** 2216 2217以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2218 2219| 错误码ID | 错误信息 | 2220| ------- | -------------------------------------------- | 2221| 1300002 | This window state is abnormal. | 2222| 1300003 | This window manager service works abnormally. | 2223 2224**示例:** 2225 2226```ts 2227import { BusinessError } from '@ohos.base'; 2228 2229try { 2230 let promise = windowClass.resize(500, 1000); 2231 promise.then(() => { 2232 console.info('Succeeded in changing the window size.'); 2233 }).catch((err: BusinessError) => { 2234 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 2235 }); 2236} catch (exception) { 2237 console.error('Failed to change the window size. Cause: ' + JSON.stringify(exception)); 2238} 2239``` 2240 2241### setWindowMode<sup>9+</sup> 2242 2243setWindowMode(mode: WindowMode, callback: AsyncCallback<void>): void 2244 2245设置窗口模式,使用callback异步回调。 2246 2247**系统接口:** 此接口为系统接口。 2248 2249**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2250 2251**参数:** 2252 2253| 参数名 | 类型 | 必填 | 说明 | 2254| -------- | -------------------------- | -- | --------- | 2255| mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | 2256| callback | AsyncCallback<void> | 是 | 回调函数。 | 2257 2258**错误码:** 2259 2260以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2261 2262| 错误码ID | 错误信息 | 2263| ------- | -------------------------------------------- | 2264| 1300002 | This window state is abnormal. | 2265| 1300003 | This window manager service works abnormally. | 2266 2267**示例:** 2268 2269```ts 2270import { BusinessError } from '@ohos.base'; 2271 2272let mode = window.WindowMode.FULLSCREEN; 2273try { 2274 windowClass.setWindowMode(mode, (err: BusinessError) => { 2275 const errCode: number = err.code; 2276 if (errCode) { 2277 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err)); 2278 return; 2279 } 2280 console.info('Succeeded in setting the window mode.'); 2281 }); 2282} catch (exception) { 2283 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception)); 2284} 2285``` 2286 2287### setWindowMode<sup>9+</sup> 2288 2289setWindowMode(mode: WindowMode): Promise<void> 2290 2291设置窗口类型,使用Promise异步回调。 2292 2293**系统接口:** 此接口为系统接口。 2294 2295**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2296 2297**参数:** 2298 2299| 参数名 | 类型 | 必填 | 说明 | 2300| -------- | -------------------------- | -- | --------- | 2301| mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | 2302 2303**返回值:** 2304 2305| 类型 | 说明 | 2306| ------------------- | ----------------------- | 2307| Promise<void> | 无返回结果的Promise对象。 | 2308 2309**错误码:** 2310 2311以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2312 2313| 错误码ID | 错误信息 | 2314| ------- | -------------------------------------------- | 2315| 1300002 | This window state is abnormal. | 2316| 1300003 | This window manager service works abnormally. | 2317 2318**示例:** 2319 2320```ts 2321import { BusinessError } from '@ohos.base'; 2322 2323let mode = window.WindowMode.FULLSCREEN; 2324try { 2325 let promise = windowClass.setWindowMode(mode); 2326 promise.then(() => { 2327 console.info('Succeeded in setting the window mode.'); 2328 }).catch((err: BusinessError) => { 2329 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(err)); 2330 }); 2331} catch (exception) { 2332 console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception)); 2333} 2334``` 2335 2336### getWindowProperties<sup>9+</sup> 2337 2338getWindowProperties(): WindowProperties 2339 2340获取当前窗口的属性,返回WindowProperties。 2341 2342**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2343 2344**返回值:** 2345 2346| 类型 | 说明 | 2347| ------------------------------------- | ------------- | 2348| [WindowProperties](#windowproperties) | 当前窗口属性。 | 2349 2350**错误码:** 2351 2352以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2353 2354| 错误码ID | 错误信息 | 2355| ------- | ------------------------------ | 2356| 1300002 | This window state is abnormal. | 2357 2358**示例:** 2359 2360```ts 2361try { 2362 let properties = windowClass.getWindowProperties(); 2363} catch (exception) { 2364 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); 2365} 2366``` 2367 2368### getWindowAvoidArea<sup>9+</sup> 2369 2370getWindowAvoidArea(type: AvoidAreaType): AvoidArea 2371 2372获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 2373 2374**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2375 2376**参数:** 2377 2378| 参数名 | 类型 | 必填 | 说明 | 2379| ---- |----------------------------------| -- | ------------------------------------------------------------ | 2380| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 2381 2382**返回值:** 2383 2384| 类型 | 说明 | 2385|--------------------------| ----------------- | 2386| [AvoidArea](#avoidarea7) | 窗口内容规避区域。 | 2387 2388**错误码:** 2389 2390以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2391 2392| 错误码ID | 错误信息 | 2393| ------- | ------------------------------ | 2394| 1300002 | This window state is abnormal. | 2395 2396**示例:** 2397 2398```ts 2399let type = window.AvoidAreaType.TYPE_SYSTEM; 2400try { 2401 let avoidArea = windowClass.getWindowAvoidArea(type); 2402} catch (exception) { 2403 console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception)); 2404} 2405``` 2406 2407### setWindowLayoutFullScreen<sup>9+</sup> 2408 2409setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 2410 2411设置窗口的布局是否为沉浸式布局,使用callback异步回调。 2412沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 2413非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。 2414 2415**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2416 2417**参数:** 2418 2419| 参数名 | 类型 | 必填 | 说明 | 2420| ------------------ | ------------------------- | -- | --------- | 2421| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 2422| callback | AsyncCallback<void> | 是 | 回调函数。 | 2423 2424**错误码:** 2425 2426以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2427 2428| 错误码ID | 错误信息 | 2429| ------- | -------------------------------------------- | 2430| 1300002 | This window state is abnormal. | 2431| 1300003 | This window manager service works abnormally. | 2432 2433**示例:** 2434 2435```ts 2436import { BusinessError } from '@ohos.base'; 2437 2438let isLayoutFullScreen = true; 2439try { 2440 windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 2441 const errCode: number = err.code; 2442 if (errCode) { 2443 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 2444 return; 2445 } 2446 console.info('Succeeded in setting the window layout to full-screen mode.'); 2447 }); 2448} catch (exception) { 2449 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 2450} 2451``` 2452 2453### setWindowLayoutFullScreen<sup>9+</sup> 2454 2455setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 2456 2457设置窗口的布局是否为沉浸式布局,使用Promise异步回调。 2458沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 2459非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。 2460 2461**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2462 2463**参数:** 2464 2465| 参数名 | 类型 | 必填 | 说明 | 2466| ------------------ | ------- | -- | ------------------------------------------------------------------------------------------------ | 2467| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局状态栏、导航栏仍然显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 2468 2469**返回值:** 2470 2471| 类型 | 说明 | 2472| ------------------- | ------------------------ | 2473| Promise<void> | 无返回结果的Promise对象。 | 2474 2475**错误码:** 2476 2477以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2478 2479| 错误码ID | 错误信息 | 2480| ------- | -------------------------------------------- | 2481| 1300002 | This window state is abnormal. | 2482| 1300003 | This window manager service works abnormally. | 2483 2484**示例:** 2485 2486```ts 2487import { BusinessError } from '@ohos.base'; 2488 2489let isLayoutFullScreen = true; 2490try { 2491 let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); 2492 promise.then(() => { 2493 console.info('Succeeded in setting the window layout to full-screen mode.'); 2494 }).catch((err: BusinessError) => { 2495 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 2496 }); 2497} catch (exception) { 2498 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 2499} 2500``` 2501 2502### setWindowSystemBarEnable<sup>9+</sup> 2503 2504setWindowSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 2505 2506设置窗口全屏模式时导航栏、状态栏的可见模式,使用callback异步回调。 2507 2508**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2509 2510**参数:** 2511 2512| 参数名 | 类型 | 必填 | 说明 | 2513| -------- | ---------------------------- | -- | --------- | 2514| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 2515| callback | AsyncCallback<void> | 是 | 回调函数。 | 2516 2517**错误码:** 2518 2519以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2520 2521| 错误码ID | 错误信息 | 2522| ------- | -------------------------------------------- | 2523| 1300002 | This window state is abnormal. | 2524| 1300003 | This window manager service works abnormally. | 2525 2526**示例:** 2527 2528```ts 2529// 此处以不显示导航栏、状态栏为例 2530import { BusinessError } from '@ohos.base'; 2531 2532let names: Array<'status' | 'navigation'> = []; 2533try { 2534 windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => { 2535 const errCode: number = err.code; 2536 if (errCode) { 2537 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 2538 return; 2539 } 2540 console.info('Succeeded in setting the system bar to be invisible.'); 2541 }); 2542} catch (exception) { 2543 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 2544} 2545``` 2546 2547### setWindowSystemBarEnable<sup>9+</sup> 2548 2549setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 2550 2551设置窗口全屏模式时导航栏、状态栏的可见模式,使用Promise异步回调。 2552 2553**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2554 2555**参数:** 2556 2557| 参数名 | 类型 | 必填 | 说明 | 2558| ----- | ---------------------------- | -- | --------------------------------- | 2559| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 2560 2561**返回值:** 2562 2563| 类型 | 说明 | 2564| ------------------- | ------------------------ | 2565| Promise<void> | 无返回结果的Promise对象。 | 2566 2567**错误码:** 2568 2569以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2570 2571| 错误码ID | 错误信息 | 2572| ------- | -------------------------------------------- | 2573| 1300002 | This window state is abnormal. | 2574| 1300003 | This window manager service works abnormally. | 2575 2576**示例:** 2577 2578```ts 2579// 此处以不显示导航栏、状态栏为例 2580import { BusinessError } from '@ohos.base'; 2581 2582let names: Array<'status' | 'navigation'> = []; 2583try { 2584 let promise = windowClass.setWindowSystemBarEnable(names); 2585 promise.then(() => { 2586 console.info('Succeeded in setting the system bar to be invisible.'); 2587 }).catch((err: BusinessError) => { 2588 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 2589 }); 2590} catch (exception) { 2591 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 2592} 2593``` 2594 2595### setWindowSystemBarProperties<sup>9+</sup> 2596 2597setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 2598 2599设置窗口全屏模式时窗口内导航栏、状态栏的属性,使用callback异步回调。 2600 2601**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2602 2603**参数:** 2604 2605| 参数名 | 类型 | 必填 | 说明 | 2606| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2607| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 2608| callback | AsyncCallback<void> | 是 | 回调函数。 | 2609 2610**错误码:** 2611 2612以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2613 2614| 错误码ID | 错误信息 | 2615| ------- | -------------------------------------------- | 2616| 1300002 | This window state is abnormal. | 2617| 1300003 | This window manager service works abnormally. | 2618 2619**示例:** 2620 2621```ts 2622import { BusinessError } from '@ohos.base'; 2623 2624let SystemBarProperties: window.SystemBarProperties = { 2625 statusBarColor: '#ff00ff', 2626 navigationBarColor: '#00ff00', 2627 //以下两个属性从API Version8开始支持 2628 statusBarContentColor: '#ffffff', 2629 navigationBarContentColor: '#00ffff' 2630}; 2631try { 2632 windowClass.setWindowSystemBarProperties(SystemBarProperties, (err: BusinessError) => { 2633 const errCode: number = err.code; 2634 if (errCode) { 2635 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 2636 return; 2637 } 2638 console.info('Succeeded in setting the system bar properties.'); 2639 }); 2640} catch (exception) { 2641 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 2642} 2643``` 2644 2645### setWindowSystemBarProperties<sup>9+</sup> 2646 2647setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 2648 2649设置窗口全屏模式时窗口内导航栏、状态栏的属性,使用Promise异步回调。 2650 2651**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2652 2653**参数:** 2654 2655| 参数名 | 类型 | 必填 | 说明 | 2656| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2657| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 2658 2659**返回值:** 2660 2661| 类型 | 说明 | 2662| ------------------- | ------------------------- | 2663| Promise<void> | 无返回结果的Promise对象。 | 2664 2665**错误码:** 2666 2667以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2668 2669| 错误码ID | 错误信息 | 2670| ------- | -------------------------------------------- | 2671| 1300002 | This window state is abnormal. | 2672| 1300003 | This window manager service works abnormally. | 2673 2674**示例:** 2675 2676```ts 2677import { BusinessError } from '@ohos.base'; 2678 2679let SystemBarProperties: window.SystemBarProperties = { 2680 statusBarColor: '#ff00ff', 2681 navigationBarColor: '#00ff00', 2682 //以下两个属性从API Version8开始支持 2683 statusBarContentColor: '#ffffff', 2684 navigationBarContentColor: '#00ffff' 2685}; 2686try { 2687 let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties); 2688 promise.then(() => { 2689 console.info('Succeeded in setting the system bar properties.'); 2690 }).catch((err: BusinessError) => { 2691 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 2692 }); 2693} catch (exception) { 2694 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(exception)); 2695} 2696``` 2697 2698### setPreferredOrientation<sup>9+</sup> 2699 2700setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void 2701 2702设置窗口的显示方向属性,使用callback异步回调。 2703 2704**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2705 2706**参数:** 2707 2708| 参数名 | 类型 | 必填 | 说明 | 2709| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2710| Orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2711| callback | AsyncCallback<void> | 是 | 回调函数。 | 2712 2713**错误码:** 2714 2715以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2716 2717| 错误码ID | 错误信息 | 2718| ------- | ------------------------------ | 2719| 1300002 | This window state is abnormal. | 2720 2721**示例:** 2722 2723```ts 2724import { BusinessError } from '@ohos.base'; 2725 2726let orientation = window.Orientation.AUTO_ROTATION; 2727try { 2728 windowClass.setPreferredOrientation(orientation, (err: BusinessError) => { 2729 const errCode: number = err.code; 2730 if (errCode) { 2731 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(err)); 2732 return; 2733 } 2734 console.info('Succeeded in setting window orientation.'); 2735 }); 2736} catch (exception) { 2737 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 2738} 2739``` 2740 2741### setPreferredOrientation<sup>9+</sup> 2742 2743setPreferredOrientation(orientation: Orientation): Promise<void> 2744 2745设置窗口的显示方向属性,使用Promise异步回调。 2746 2747**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2748 2749**参数:** 2750 2751| 参数名 | 类型 | 必填 | 说明 | 2752| ------------------- | ------------------------------------------- | ---- | ---------------------- | 2753| Orientation | [Orientation](#orientation9) | 是 | 窗口显示方向的属性。 | 2754 2755**返回值:** 2756 2757| 类型 | 说明 | 2758| ------------------- | ------------------------- | 2759| Promise<void> | 无返回结果的Promise对象。 | 2760 2761**错误码:** 2762 2763以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2764 2765| 错误码ID | 错误信息 | 2766| ------- | ------------------------------ | 2767| 1300002 | This window state is abnormal. | 2768 2769**示例:** 2770 2771```ts 2772import { BusinessError } from '@ohos.base'; 2773 2774let orientation = window.Orientation.AUTO_ROTATION; 2775try { 2776 let promise = windowClass.setPreferredOrientation(orientation); 2777 promise.then(() => { 2778 console.info('Succeeded in setting the window orientation.'); 2779 }).catch((err: BusinessError) => { 2780 console.error('Failed to set the window orientation. Cause: ' + JSON.stringify(err)); 2781 }); 2782} catch (exception) { 2783 console.error('Failed to set window orientation. Cause: ' + JSON.stringify(exception)); 2784} 2785``` 2786 2787### getUIContext<sup>10+</sup> 2788 2789getUIContext(): UIContext 2790 2791获取UIContext实例。 2792 2793**模型约束:** 此接口仅可在Stage模型下使用。 2794 2795**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2796 2797**返回值:** 2798 2799| 类型 | 说明 | 2800| ---------- | ---------------------- | 2801| [UIContext](./js-apis-arkui-UIContext.md#uicontext) | 返回UIContext实例对象。 | 2802 2803**错误码:** 2804 2805以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2806 2807| 错误码ID | 错误信息 | 2808| ------- | ------------------------------ | 2809| 1300002 | This window state is abnormal. | 2810 2811**示例:** 2812 2813```ts 2814import UIAbility from '@ohos.app.ability.UIAbility'; 2815import window from '@ohos.window'; 2816import { BusinessError } from '@ohos.base'; 2817import { UIContext } from '@ohos.arkui.UIContext'; 2818 2819export default class EntryAbility extends UIAbility { 2820 onWindowStageCreate(windowStage: window.WindowStage) { 2821 // 为主窗口加载对应的目标页面。 2822 windowStage.loadContent("pages/page2", (err: BusinessError) => { 2823 let errCode: number = err.code; 2824 if (errCode) { 2825 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2826 return; 2827 } 2828 console.info('Succeeded in loading the content.'); 2829 // 获取应用主窗口。 2830 let windowClass: window.Window | undefined = undefined; 2831 windowStage.getMainWindow((err: BusinessError, data) => { 2832 let errCode: number = err.code; 2833 if (errCode) { 2834 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 2835 return; 2836 } 2837 windowClass = data; 2838 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 2839 // 获取UIContext实例。 2840 let uiContext: UIContext | null = null; 2841 uiContext = windowClass.getUIContext(); 2842 }) 2843 }); 2844 } 2845}; 2846``` 2847 2848### setUIContent<sup>9+</sup> 2849 2850setUIContent(path: string, callback: AsyncCallback<void>): void 2851 2852根据当前工程中某个页面的路径为窗口加载具体页面内容,使用callback异步回调。 2853 2854**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2855 2856**参数:** 2857 2858| 参数名 | 类型 | 必填 | 说明 | 2859| -------- | ------------------------- | -- | -------------------- | 2860| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 2861| callback | AsyncCallback<void> | 是 | 回调函数。 | 2862 2863**错误码:** 2864 2865以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2866 2867| 错误码ID | 错误信息 | 2868| ------- | -------------------------------------------- | 2869| 1300002 | This window state is abnormal. | 2870| 1300003 | This window manager service works abnormally. | 2871 2872**示例:** 2873 2874```ts 2875import { BusinessError } from '@ohos.base'; 2876 2877try { 2878 windowClass.setUIContent('pages/page2/page3', (err: BusinessError) => { 2879 const errCode: number = err.code; 2880 if (errCode) { 2881 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2882 return; 2883 } 2884 console.info('Succeeded in loading the content.'); 2885 }); 2886} catch (exception) { 2887 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2888} 2889``` 2890 2891### setUIContent<sup>9+</sup> 2892 2893setUIContent(path: string): Promise<void> 2894 2895根据当前工程中某个页面的路径为窗口加载具体页面内容,使用Promise异步回调。 2896 2897**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2898 2899**参数:** 2900 2901| 参数名 | 类型 | 必填 | 说明 | 2902| ---- | ------ | -- | ------------------ | 2903| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 2904 2905**返回值:** 2906 2907| 类型 | 说明 | 2908| ------------------- | ------------------------ | 2909| Promise<void> | 无返回结果的Promise对象。 | 2910 2911**错误码:** 2912 2913以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2914 2915| 错误码ID | 错误信息 | 2916| ------- | -------------------------------------------- | 2917| 1300002 | This window state is abnormal. | 2918| 1300003 | This window manager service works abnormally. | 2919 2920**示例:** 2921 2922```ts 2923import { BusinessError } from '@ohos.base'; 2924 2925try { 2926 let promise = windowClass.setUIContent('pages/page2/page3'); 2927 promise.then(() => { 2928 console.info('Succeeded in loading the content.'); 2929 }).catch((err: BusinessError) => { 2930 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 2931 }); 2932} catch (exception) { 2933 console.error('Failed to load the content. Cause: ' + JSON.stringify(exception)); 2934} 2935``` 2936 2937### loadContent<sup>9+</sup> 2938 2939loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 2940 2941根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。 2942 2943**模型约束:** 此接口仅可在Stage模型下使用。 2944 2945**系统能力:** SystemCapability.WindowManager.WindowManager.Core 2946 2947**参数:** 2948 2949| 参数名 | 类型 | 必填 | 说明 | 2950| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2951| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 2952| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 2953| callback | AsyncCallback<void> | 是 | 回调函数。 | 2954 2955**错误码:** 2956 2957以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 2958 2959| 错误码ID | 错误信息 | 2960| ------- | -------------------------------------------- | 2961| 1300002 | This window state is abnormal. | 2962| 1300003 | This window manager service works abnormally. | 2963 2964**示例:** 2965 2966```ts 2967import UIAbility from '@ohos.app.ability.UIAbility'; 2968import window from '@ohos.window'; 2969import { BusinessError } from '@ohos.base'; 2970 2971export default class EntryAbility extends UIAbility { 2972 // ... 2973 2974 onWindowStageCreate(windowStage: window.WindowStage) { 2975 console.log('onWindowStageCreate'); 2976 let storage: LocalStorage = new LocalStorage(); 2977 storage.setOrCreate('storageSimpleProp', 121); 2978 try { 2979 if (!windowClass) { 2980 console.info('Failed to load the content. Cause: windowClass is null'); 2981 } 2982 else { 2983 (windowClass as window.Window).loadContent('pages/page2', storage, (err: BusinessError) => { 2984 const errCode: number = err.code; 2985 if (errCode) { 2986 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 2987 return; 2988 } 2989 console.info('Succeeded in loading the content.'); 2990 }); 2991 } 2992 } catch (exception) { 2993 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 2994 } 2995 } 2996}; 2997``` 2998 2999### loadContent<sup>9+</sup> 3000 3001loadContent(path: string, storage: LocalStorage): Promise<void> 3002 3003根据当前工程中某个页面的路径为窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。 3004 3005**模型约束:** 此接口仅可在Stage模型下使用。 3006 3007**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3008 3009**参数:** 3010 3011| 参数名 | 类型 | 必填 | 说明 | 3012| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 3013| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 3014| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 3015 3016**返回值:** 3017 3018| 类型 | 说明 | 3019| ------------------- | ------------------------- | 3020| Promise<void> | 无返回结果的Promise对象。 | 3021 3022**错误码:** 3023 3024以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3025 3026| 错误码ID | 错误信息 | 3027| ------- | -------------------------------------------- | 3028| 1300002 | This window state is abnormal. | 3029| 1300003 | This window manager service works abnormally. | 3030 3031**示例:** 3032 3033```ts 3034import UIAbility from '@ohos.app.ability.UIAbility'; 3035import window from '@ohos.window'; 3036import { BusinessError } from '@ohos.base'; 3037 3038export default class EntryAbility extends UIAbility { 3039 // ... 3040 3041 onWindowStageCreate(windowStage: window.WindowStage) { 3042 console.log('onWindowStageCreate'); 3043 let storage: LocalStorage = new LocalStorage(); 3044 storage.setOrCreate('storageSimpleProp', 121); 3045 try { 3046 if (!windowClass) { 3047 console.info('Failed to load the content. Cause: windowClass is null'); 3048 } 3049 else { 3050 let promise = (windowClass as window.Window).loadContent('pages/page2', storage); 3051 promise.then(() => { 3052 console.info('Succeeded in loading the content.'); 3053 }).catch((err: BusinessError) => { 3054 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 3055 }); 3056 } 3057 } catch (exception) { 3058 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 3059 } 3060 } 3061}; 3062``` 3063 3064### isWindowShowing<sup>9+</sup> 3065 3066isWindowShowing(): boolean 3067 3068判断当前窗口是否已显示。 3069 3070**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3071 3072**返回值:** 3073 3074| 类型 | 说明 | 3075| ------- | ------------------------------------------------------------------ | 3076| boolean | 当前窗口是否已显示。true表示当前窗口已显示,false则表示当前窗口未显示。 | 3077 3078**错误码:** 3079 3080以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3081 3082| 错误码ID | 错误信息 | 3083| ------- | ------------------------------ | 3084| 1300002 | This window state is abnormal. | 3085 3086**示例:** 3087 3088```ts 3089try { 3090 let data = windowClass.isWindowShowing(); 3091 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 3092} catch (exception) { 3093 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(exception)); 3094} 3095``` 3096 3097### on('windowSizeChange')<sup>7+</sup> 3098 3099on(type: 'windowSizeChange', callback: Callback<Size>): void 3100 3101开启窗口尺寸变化的监听。 3102 3103**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3104 3105**参数:** 3106 3107| 参数名 | 类型 | 必填 | 说明 | 3108| -------- | ------------------------------ | ---- | -------------------------------------------------------- | 3109| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3110| callback | Callback<[Size](#size7)> | 是 | 回调函数。返回当前的窗口尺寸。 | 3111 3112**示例:** 3113 3114```ts 3115try { 3116 windowClass.on('windowSizeChange', (data) => { 3117 console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 3118 }); 3119} catch (exception) { 3120 console.error('Failed to enable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 3121} 3122``` 3123 3124### off('windowSizeChange')<sup>7+</sup> 3125 3126off(type: 'windowSizeChange', callback?: Callback<Size>): void 3127 3128关闭窗口尺寸变化的监听。 3129 3130**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3131 3132**参数:** 3133 3134| 参数名 | 类型 | 必填 | 说明 | 3135| -------- | ----------------------------- | ---- | -------------------------------------------------------- | 3136| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 | 3137| callback | Callback<[Size](#size7)> | 否 | 回调函数。返回当前的窗口尺寸。如果传入参数,则关闭该监听。如果未传入参数,则关闭窗口尺寸变化的监听。 | 3138 3139**示例:** 3140 3141```ts 3142try { 3143 windowClass.off('windowSizeChange'); 3144} catch (exception) { 3145 console.error('Failed to disable the listener for window size changes. Cause: ' + JSON.stringify(exception)); 3146} 3147``` 3148 3149### on('avoidAreaChange')<sup>9+</sup> 3150 3151on(type: 'avoidAreaChange', callback: Callback<{ type: AvoidAreaType, area: AvoidArea}>): void 3152 3153开启系统规避区变化的监听。 3154 3155**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3156 3157**参数:** 3158 3159| 参数名 | 类型 | 必填 | 说明 | 3160| -------- |------------------------------------------------------------------| ---- |--------------------------------------| 3161| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3162| callback | Callback<{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }> | 是 | 回调函数。返回当前规避区以及规避区类型。| 3163 3164**示例:** 3165 3166```ts 3167try { 3168 windowClass.on('avoidAreaChange', (data) => { 3169 console.info('Succeeded in enabling the listener for system avoid area changes. type:' + 3170 JSON.stringify(data.type) + ', area: ' + JSON.stringify(data.area)); 3171 }); 3172} catch (exception) { 3173 console.error('Failed to enable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 3174} 3175``` 3176 3177### off('avoidAreaChange')<sup>9+</sup> 3178 3179off(type: 'avoidAreaChange', callback?: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void 3180 3181关闭系统规避区变化的监听。 3182 3183**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3184 3185**参数:** 3186 3187| 参数名 | 类型 | 必填 | 说明 | 3188| -------- |-----------------------------------------------------------------------------|-----|------------------------------------| 3189| type | string | 是 | 监听事件,固定为'avoidAreaChange',即系统规避区变化事件。 | 3190| callback | Callback<{ type: [AvoidAreaType](#avoidareatype7), area: [AvoidArea](#avoidarea7) }> | 否 | 回调函数。返回当前规避区以及规避区类型。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有系统规避区变化的监听。| 3191 3192**示例:** 3193 3194```ts 3195try { 3196 windowClass.off('avoidAreaChange'); 3197} catch (exception) { 3198 console.error('Failed to disable the listener for system avoid area changes. Cause: ' + JSON.stringify(exception)); 3199} 3200``` 3201 3202### on('keyboardHeightChange')<sup>7+</sup> 3203 3204on(type: 'keyboardHeightChange', callback: Callback<number>): void 3205 3206开启固定态输入法窗口软键盘高度变化的监听。从API version 10开始,改变输入法窗口为固定态或者悬浮态方法详细介绍请参见[输入法服务](js-apis-inputmethodengine.md#changeflag10)。 3207 3208**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3209 3210**参数:** 3211 3212| 参数名 | 类型 | 必填 | 说明 | 3213| -------- | ------------------- | ---- |-------------------------------------------| 3214| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3215| callback | Callback<number> | 是 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。 | 3216 3217**示例:** 3218 3219```ts 3220try { 3221 windowClass.on('keyboardHeightChange', (data) => { 3222 console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); 3223 }); 3224} catch (exception) { 3225 console.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 3226} 3227``` 3228 3229### off('keyboardHeightChange')<sup>7+</sup> 3230 3231off(type: 'keyboardHeightChange', callback?: Callback<number>): void 3232 3233关闭固定态输入法窗口软键盘高度变化的监听。从API version 10开始,改变输入法窗口为固定态或者悬浮态方法详细介绍请参见[输入法服务](js-apis-inputmethodengine.md#changeflag10)。 3234 3235**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3236 3237**参数:** 3238 3239| 参数名 | 类型 | 必填 | 说明 | 3240| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3241| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 | 3242| callback | Callback<number> | 否 | 回调函数。返回当前的键盘高度,返回值为整数,单位为px。若传入参数,则关闭该监听。如果未传入参数,则关闭所有固定态输入法窗口软键盘高度变化的监听。 | 3243 3244**示例:** 3245 3246```ts 3247try { 3248 windowClass.off('keyboardHeightChange'); 3249} catch (exception) { 3250 console.error('Failed to disable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception)); 3251} 3252``` 3253 3254### on('touchOutside')<sup>9+</sup> 3255 3256on(type: 'touchOutside', callback: Callback<void>): void 3257 3258开启本窗口区域范围外的点击事件的监听。 3259 3260**系统接口:** 此接口为系统接口。 3261 3262**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3263 3264**参数:** 3265 3266| 参数名 | 类型 | 必填 | 说明 | 3267| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3268| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 3269| callback | Callback<void> | 是 | 回调函数。当点击事件发生在本窗口范围之外的回调。 | 3270 3271**示例:** 3272 3273```ts 3274try { 3275 windowClass.on('touchOutside', () => { 3276 console.info('touch outside'); 3277 }); 3278} catch (exception) { 3279 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3280} 3281``` 3282 3283### off('touchOutside')<sup>9+</sup> 3284 3285off(type: 'touchOutside', callback?: Callback<void>): void 3286 3287关闭本窗口区域范围外的点击事件的监听。 3288 3289**系统接口:** 此接口为系统接口。 3290 3291**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3292 3293**参数:** 3294 3295| 参数名 | 类型 | 必填 | 说明 | 3296| -------- |----------------------| ---- |--------------------------------------| 3297| type | string | 是 | 监听事件,固定为'touchOutside',即本窗口范围外的点击事件。 | 3298| callback | Callback<void> | 否 | 回调函数。当点击事件发生在本窗口范围之外的回调。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有本窗口区域范围外的点击事件的监听。 | 3299 3300**示例:** 3301 3302```ts 3303try { 3304 windowClass.off('touchOutside'); 3305} catch (exception) { 3306 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3307} 3308``` 3309 3310### on('screenshot')<sup>9+</sup> 3311 3312on(type: 'screenshot', callback: Callback<void>): void 3313 3314开启截屏事件的监听。 3315 3316**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3317 3318**参数:** 3319 3320| 参数名 | 类型 | 必填 | 说明 | 3321| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3322| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 3323| callback | Callback<void> | 是 | 回调函数。发生截屏事件时的回调。 | 3324 3325**示例:** 3326 3327```ts 3328try { 3329 windowClass.on('screenshot', () => { 3330 console.info('screenshot happened'); 3331 }); 3332} catch (exception) { 3333 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3334} 3335``` 3336 3337### off('screenshot')<sup>9+</sup> 3338 3339off(type: 'screenshot', callback?: Callback<void>): void 3340 3341关闭截屏事件的监听。 3342 3343**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3344 3345**参数:** 3346 3347| 参数名 | 类型 | 必填 | 说明 | 3348| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3349| type | string | 是 | 监听事件,固定为'screenshot',即截屏事件。 | 3350| callback | Callback<void> | 否 | 回调函数。发生截屏事件时的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有截屏事件的监听。 | 3351 3352**示例:** 3353 3354```ts 3355let callback = () => { 3356 console.info('screenshot happened'); 3357}; 3358try { 3359 windowClass.on('screenshot', callback); 3360} catch (exception) { 3361 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3362} 3363try { 3364 windowClass.off('screenshot', callback); 3365 // 如果通过on开启多个callback进行监听,同时关闭所有监听: 3366 windowClass.off('screenshot'); 3367} catch (exception) { 3368 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3369} 3370``` 3371 3372### on('dialogTargetTouch')<sup>10+</sup> 3373 3374on(type: 'dialogTargetTouch', callback: Callback<void>): void 3375 3376开启模态窗口目标窗口的点击事件的监听。 3377 3378**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3379 3380**参数:** 3381 3382| 参数名 | 类型 | 必填 | 说明 | 3383| -------- | ------------------- | ---- | ------------------------------------------------------------ | 3384| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 | 3385| callback | Callback<void>| 是 | 回调函数。当点击事件发生在模态窗口目标窗口的回调。 | 3386 3387**示例:** 3388 3389```ts 3390try { 3391 windowClass.on('dialogTargetTouch', () => { 3392 console.info('touch dialog target'); 3393 }); 3394} catch (exception) { 3395 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3396} 3397``` 3398 3399### off('dialogTargetTouch')<sup>10+</sup> 3400 3401off(type: 'dialogTargetTouch', callback?: Callback<void>): void 3402 3403关闭模态窗口目标窗口的点击事件的监听。 3404 3405**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3406 3407**参数:** 3408 3409| 参数名 | 类型 | 必填 | 说明 | 3410| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 3411| type | string | 是 | 监听事件,固定为'dialogTargetTouch',即模态窗口目标窗口的点击事件。 | 3412| callback | Callback<void> | 否 | 回调函数。当点击事件发生在模态窗口目标窗口的回调。若传入参数,则关闭该监听。若未传入参数,则关闭所有模态窗口目标窗口的点击事件的监听。 | 3413 3414**示例:** 3415 3416```ts 3417try { 3418 windowClass.off('dialogTargetTouch'); 3419} catch (exception) { 3420 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3421} 3422``` 3423 3424### on('windowEvent')<sup>10+</sup> 3425 3426on(type: 'windowEvent', callback: Callback<WindowEventType>): void 3427 3428开启窗口生命周期变化的监听。 3429 3430**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3431 3432**参数:** 3433 3434| 参数名 | 类型 | 必填 | 说明 | 3435| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3436| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 3437| callback | Callback<[WindowEventType](#windoweventtype10)> | 是 | 回调函数。返回当前的窗口生命周期状态。 | 3438 3439**示例:** 3440 3441```ts 3442try { 3443 windowClass.on('windowEvent', (data) => { 3444 console.info('Window event happened. Event:' + JSON.stringify(data)); 3445 }); 3446} catch (exception) { 3447 console.error('Failed to register callback. Cause: ' + JSON.stringify(exception)); 3448} 3449``` 3450 3451### off('windowEvent')<sup>10+</sup> 3452 3453off(type: 'windowEvent', callback?: Callback<WindowEventType >): void 3454 3455关闭窗口生命周期变化的监听。 3456 3457**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3458 3459**参数:** 3460 3461| 参数名 | 类型 | 必填 | 说明 | 3462| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3463| type | string | 是 | 监听事件,固定为'windowEvent',即窗口生命周期变化事件。 | 3464| callback | Callback<[WindowEventType](#windoweventtype10)> | 否 | 回调函数。返回当前的窗口生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有窗口生命周期变化的监听。 | 3465 3466**示例:** 3467 3468```ts 3469try { 3470 windowClass.off('windowEvent'); 3471} catch (exception) { 3472 console.error('Failed to unregister callback. Cause: ' + JSON.stringify(exception)); 3473} 3474``` 3475 3476### bindDialogTarget<sup>9+</sup> 3477 3478bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 3479 3480绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 3481 3482**系统接口:** 此接口为系统接口。 3483 3484**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3485 3486**参数:** 3487 3488| 参数名 | 类型 | 必填 | 说明 | 3489| ----------- | ------------------------- | ---- | -------------------- | 3490| token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | 3491| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 3492| callback | AsyncCallback<void> | 是 | 回调函数。 | 3493 3494**错误码:** 3495 3496以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3497 3498| 错误码ID | 错误信息 | 3499| ------- | -------------------------------------------- | 3500| 1300002 | This window state is abnormal. | 3501| 1300003 | This window manager service works abnormally. | 3502 3503**示例:** 3504 3505```ts 3506import rpc from '@ohos.rpc'; 3507import { BusinessError } from '@ohos.base'; 3508 3509class MyDeathRecipient { 3510 onRemoteDied() { 3511 console.log('server died'); 3512 } 3513} 3514 3515class TestRemoteObject extends rpc.RemoteObject { 3516 constructor(descriptor: string) { 3517 super(descriptor); 3518 } 3519 3520 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3521 return true; 3522 } 3523 3524 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3525 return true; 3526 } 3527 3528 isObjectDead(): boolean { 3529 return false; 3530 } 3531} 3532 3533let token: TestRemoteObject = new TestRemoteObject('testObject'); 3534let windowClass: window.Window | undefined = undefined; 3535let config: window.Configuration = { name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; 3536try { 3537 window.createWindow(config, (err: BusinessError, data) => { 3538 let errCode: number = err.code; 3539 if (errCode) { 3540 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3541 return; 3542 } 3543 windowClass = data; 3544 }); 3545 windowClass.bindDialogTarget(token, () => { 3546 console.info('Dialog Window Need Destroy.'); 3547 }, (err: BusinessError) => { 3548 let errCode: number = err.code; 3549 if (errCode) { 3550 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3551 return; 3552 } 3553 console.info('Succeeded in binding dialog target.'); 3554 }); 3555} catch (exception) { 3556 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception)); 3557} 3558``` 3559 3560### bindDialogTarget<sup>9+</sup> 3561 3562bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void> 3563 3564绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 3565 3566**系统接口:** 此接口为系统接口。 3567 3568**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3569 3570**参数:** 3571 3572| 参数名 | 类型 | 必填 | 说明 | 3573| ----------- | ------------------------- | ---- | -------------------- | 3574| token | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | 3575| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 3576 3577**返回值:** 3578 3579| 类型 | 说明 | 3580| ------------------- | ------------------------- | 3581| Promise<void> | 无返回结果的Promise对象。 | 3582 3583**错误码:** 3584 3585以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3586 3587| 错误码ID | 错误信息 | 3588| ------- | -------------------------------------------- | 3589| 1300002 | This window state is abnormal. | 3590| 1300003 | This window manager service works abnormally. | 3591 3592**示例:** 3593 3594```ts 3595import rpc from '@ohos.rpc'; 3596import { BusinessError } from '@ohos.base'; 3597 3598class MyDeathRecipient { 3599 onRemoteDied() { 3600 console.log('server died'); 3601 } 3602} 3603 3604class TestRemoteObject extends rpc.RemoteObject { 3605 constructor(descriptor: string) { 3606 super(descriptor); 3607 } 3608 3609 addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3610 return true; 3611 } 3612 3613 removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { 3614 return true; 3615 } 3616 3617 isObjectDead(): boolean { 3618 return false; 3619 } 3620} 3621 3622let token: TestRemoteObject = new TestRemoteObject('testObject'); 3623let windowClass: window.Window | undefined = undefined; 3624let config: window.Configuration = { 3625 name: "test", 3626 windowType: window.WindowType.TYPE_DIALOG, 3627 ctx: this.context 3628}; 3629try { 3630 window.createWindow(config, (err: BusinessError, data) => { 3631 const errCode: number = err.code; 3632 if (errCode) { 3633 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3634 return; 3635 } 3636 windowClass = data; 3637 }); 3638 let promise = windowClass.bindDialogTarget(token, () => { 3639 console.info('Dialog Window Need Destroy.'); 3640 }); 3641 promise.then(() => { 3642 console.info('Succeeded in binding dialog target.'); 3643 }).catch((err: BusinessError) => { 3644 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3645 }); 3646} catch (exception) { 3647 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception)); 3648} 3649``` 3650 3651### bindDialogTarget<sup>9+</sup> 3652 3653bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 3654 3655绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 3656 3657**系统接口:** 此接口为系统接口。 3658 3659**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3660 3661**参数:** 3662 3663| 参数名 | 类型 | 必填 | 说明 | 3664| ----------- | ------------------------- | ---- | -------------------- | 3665| requestInfo | [dialogRequest.RequestInfo](js-apis-app-ability-dialogRequest.md#requestinfo) | 是 | 目标窗口RequestInfo值。 | 3666| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 3667| callback | AsyncCallback<void> | 是 | 回调函数。 | 3668 3669**错误码:** 3670 3671以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3672 3673| 错误码ID | 错误信息 | 3674| ------- | -------------------------------------------- | 3675| 1300002 | This window state is abnormal. | 3676| 1300003 | This window manager service works abnormally. | 3677 3678**示例:** 3679 3680```ts 3681import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; 3682import dialogRequest from '@ohos.app.ability.dialogRequest'; 3683import Want from '@ohos.app.ability.Want'; 3684import { BusinessError } from '@ohos.base'; 3685 3686export default class ServiceExtAbility extends ServiceExtensionAbility { 3687 onRequest(want: Want, startId: number) { 3688 console.info('onRequest'); 3689 let windowClass: window.Window | undefined = undefined; 3690 let config: window.Configuration = { 3691 name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context 3692 }; 3693 try { 3694 window.createWindow(config, (err: BusinessError, data) => { 3695 let errCode: number = err.code; 3696 if (errCode) { 3697 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3698 return; 3699 } 3700 windowClass = data; 3701 }); 3702 let requestInfo = dialogRequest.getRequestInfo(want) 3703 windowClass.bindDialogTarget(requestInfo, () => { 3704 console.info('Dialog Window Need Destroy.'); 3705 }, (err: BusinessError) => { 3706 let errCode: number = err.code; 3707 if (errCode) { 3708 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3709 return; 3710 } 3711 console.info('Succeeded in binding dialog target.'); 3712 }); 3713 } catch (err) { 3714 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)) 3715 } 3716 } 3717} 3718``` 3719 3720### bindDialogTarget<sup>9+</sup> 3721 3722bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>): Promise<void> 3723 3724绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 3725 3726**系统接口:** 此接口为系统接口。 3727 3728**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3729 3730**参数:** 3731 3732| 参数名 | 类型 | 必填 | 说明 | 3733| ----------- | ------------------------- | ---- | -------------------- | 3734| requestInfo | [dialogRequest.RequestInfo](js-apis-app-ability-dialogRequest.md#requestinfo) | 是 | 目标窗口RequestInfo值。 | 3735| deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | 3736 3737**返回值:** 3738 3739| 类型 | 说明 | 3740| ------------------- | ------------------------- | 3741| Promise<void> | 无返回结果的Promise对象。 | 3742 3743**错误码:** 3744 3745以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3746 3747| 错误码ID | 错误信息 | 3748| ------- | -------------------------------------------- | 3749| 1300002 | This window state is abnormal. | 3750| 1300003 | This window manager service works abnormally. | 3751 3752**示例:** 3753 3754```ts 3755import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; 3756import dialogRequest from '@ohos.app.ability.dialogRequest'; 3757import Want from '@ohos.app.ability.Want'; 3758import { BusinessError } from '@ohos.base'; 3759 3760export default class ServiceExtAbility extends ServiceExtensionAbility { 3761 onRequest(want: Want, startId: number) { 3762 console.info('onRequest'); 3763 let windowClass: window.Window | undefined = undefined; 3764 let config: window.Configuration = { 3765 name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context 3766 }; 3767 try { 3768 window.createWindow(config, (err: BusinessError, data) => { 3769 const errCode: number = err.code; 3770 if (errCode) { 3771 console.error('Failed to create the window. Cause: ' + JSON.stringify(err)); 3772 return; 3773 } 3774 windowClass = data; 3775 }); 3776 let requestInfo = dialogRequest.getRequestInfo(want) 3777 let promise = windowClass.bindDialogTarget(requestInfo, () => { 3778 console.info('Dialog Window Need Destroy.'); 3779 }); 3780 promise.then(() => { 3781 console.info('Succeeded in binding dialog target.'); 3782 }).catch((err: BusinessError) => { 3783 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)); 3784 }); 3785 } catch (err) { 3786 console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err)) 3787 } 3788 } 3789} 3790``` 3791 3792### isWindowSupportWideGamut<sup>9+</sup> 3793 3794isWindowSupportWideGamut(callback: AsyncCallback<boolean>): void 3795 3796判断当前窗口是否支持广色域模式,使用callback异步回调。 3797 3798**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3799 3800**参数:** 3801 3802| 参数名 | 类型 | 必填 | 说明 | 3803| -------- | ---------------------------- | -- | -------------------------------------------------------------------------------- | 3804| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 3805 3806**错误码:** 3807 3808以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3809 3810| 错误码ID | 错误信息 | 3811| ------- | ------------------------------ | 3812| 1300002 | This window state is abnormal. | 3813 3814**示例:** 3815 3816```ts 3817import { BusinessError } from '@ohos.base'; 3818 3819windowClass.isWindowSupportWideGamut((err: BusinessError, data) => { 3820 const errCode: number = err.code; 3821 if (errCode) { 3822 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 3823 return; 3824 } 3825 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 3826}); 3827``` 3828 3829### isWindowSupportWideGamut<sup>9+</sup> 3830 3831isWindowSupportWideGamut(): Promise<boolean> 3832 3833判断当前窗口是否支持广色域模式,使用Promise异步回调。 3834 3835**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3836 3837**返回值:** 3838 3839| 类型 | 说明 | 3840| ---------------------- | ------------------------------------------------------------------------------------ | 3841| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 3842 3843**错误码:** 3844 3845以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3846 3847| 错误码ID | 错误信息 | 3848| ------- | ------------------------------ | 3849| 1300002 | This window state is abnormal. | 3850 3851**示例:** 3852 3853```ts 3854import { BusinessError } from '@ohos.base'; 3855 3856let promise = windowClass.isWindowSupportWideGamut(); 3857promise.then((data) => { 3858 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 3859}).catch((err: BusinessError) => { 3860 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 3861}); 3862``` 3863 3864### setWindowColorSpace<sup>9+</sup> 3865 3866setWindowColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 3867 3868设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 3869 3870**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3871 3872**参数:** 3873 3874| 参数名 | 类型 | 必填 | 说明 | 3875| ---------- | ------------------------- | -- | ----------- | 3876| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 3877| callback | AsyncCallback<void> | 是 | 回调函数。 | 3878 3879**错误码:** 3880 3881以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3882 3883| 错误码ID | 错误信息 | 3884| ------- | ------------------------------ | 3885| 1300002 | This window state is abnormal. | 3886 3887**示例:** 3888 3889```ts 3890import { BusinessError } from '@ohos.base'; 3891 3892try { 3893 windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 3894 const errCode: number = err.code; 3895 if (errCode) { 3896 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 3897 return; 3898 } 3899 console.info('Succeeded in setting window colorspace.'); 3900 }); 3901} catch (exception) { 3902 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3903} 3904``` 3905 3906### setWindowColorSpace<sup>9+</sup> 3907 3908setWindowColorSpace(colorSpace:ColorSpace): Promise<void> 3909 3910设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 3911 3912**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3913 3914**参数:** 3915 3916| 参数名 | 类型 | 必填 | 说明 | 3917| ---------- | ------------------------- | -- | ------------- | 3918| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 3919 3920**返回值:** 3921 3922| 类型 | 说明 | 3923| ------------------- | ------------------------ | 3924| Promise<void> | 无返回结果的Promise对象。 | 3925 3926**错误码:** 3927 3928以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3929 3930| 错误码ID | 错误信息 | 3931| ------- | ------------------------------ | 3932| 1300002 | This window state is abnormal. | 3933 3934**示例:** 3935 3936```ts 3937import { BusinessError } from '@ohos.base'; 3938 3939try { 3940 let promise = windowClass.setWindowColorSpace(window.ColorSpace.WIDE_GAMUT); 3941 promise.then(() => { 3942 console.info('Succeeded in setting window colorspace.'); 3943 }).catch((err: BusinessError) => { 3944 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 3945 }); 3946} catch (exception) { 3947 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(exception)); 3948} 3949``` 3950 3951### getWindowColorSpace<sup>9+</sup> 3952 3953getWindowColorSpace(): ColorSpace 3954 3955获取当前窗口色域模式。 3956 3957**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3958 3959**返回值:** 3960 3961| 类型 | 说明 | 3962| ------------------------- | ------------- | 3963| [ColorSpace](#colorspace8) | 当前色域模式。 | 3964 3965**错误码:** 3966 3967以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3968 3969| 错误码ID | 错误信息 | 3970| ------- | ------------------------------ | 3971| 1300002 | This window state is abnormal. | 3972 3973**示例:** 3974 3975```ts 3976let colorSpace = windowClass.getWindowColorSpace(); 3977``` 3978 3979### setWindowBackgroundColor<sup>9+</sup> 3980 3981setWindowBackgroundColor(color: string): void 3982 3983设置窗口的背景色。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 3984 3985**系统能力:** SystemCapability.WindowManager.WindowManager.Core 3986 3987**参数:** 3988 3989| 参数名 | 类型 | 必填 | 说明 | 3990| ----- | ------ | -- | ----------------------------------------------------------------------- | 3991| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 3992 3993**错误码:** 3994 3995以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 3996 3997| 错误码ID | 错误信息 | 3998| ------- | ------------------------------ | 3999| 1300002 | This window state is abnormal. | 4000 4001**示例:** 4002 4003```ts 4004import { BusinessError } from '@ohos.base'; 4005 4006private SetUIContent(windowClass: window.Window) { 4007 windowClass.setUIContent("pages/ButtonWindow",(err: BusinessError) => { 4008 if (err.code) { 4009 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 4010 return; 4011 } 4012 console.info('Succeeded in loading the content.'); 4013 let color: string = '#00ff33'; 4014 try { 4015 windowClass.setWindowBackgroundColor(color); 4016 } catch (exception) { 4017 console.error('Failed to set the background color. Cause: ' + JSON.stringify(exception)); 4018 }; 4019 }); 4020} 4021``` 4022 4023### setWindowBrightness<sup>9+</sup> 4024 4025setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void 4026 4027允许应用窗口设置屏幕亮度值,使用callback异步回调。 4028 4029当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 4030 4031**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4032 4033**参数:** 4034 4035| 参数名 | 类型 | 必填 | 说明 | 4036| ---------- | ------------------------- | -- |-------------------------------------------| 4037| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 4038| callback | AsyncCallback<void> | 是 | 回调函数。 | 4039 4040**错误码:** 4041 4042以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4043 4044| 错误码ID | 错误信息 | 4045| ------- | -------------------------------------------- | 4046| 1300002 | This window state is abnormal. | 4047| 1300003 | This window manager service works abnormally. | 4048 4049**示例:** 4050 4051```ts 4052import { BusinessError } from '@ohos.base'; 4053 4054let brightness: number = 1; 4055try { 4056 windowClass.setWindowBrightness(brightness, (err: BusinessError) => { 4057 const errCode: number = err.code; 4058 if (errCode) { 4059 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 4060 return; 4061 } 4062 console.info('Succeeded in setting the brightness.'); 4063 }); 4064} catch (exception) { 4065 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 4066} 4067``` 4068 4069### setWindowBrightness<sup>9+</sup> 4070 4071setWindowBrightness(brightness: number): Promise<void> 4072 4073允许应用窗口设置屏幕亮度值,使用Promise异步回调。 4074 4075当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 4076 4077**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4078 4079**参数:** 4080 4081| 参数名 | 类型 | 必填 | 说明 | 4082| ---------- | ------ | -- |----------------------------------------| 4083| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 4084 4085**返回值:** 4086 4087| 类型 | 说明 | 4088| ------------------- | ------------------------ | 4089| Promise<void> | 无返回结果的Promise对象。 | 4090 4091**错误码:** 4092 4093以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4094 4095| 错误码ID | 错误信息 | 4096| ------- | -------------------------------------------- | 4097| 1300002 | This window state is abnormal. | 4098| 1300003 | This window manager service works abnormally. | 4099 4100**示例:** 4101 4102```ts 4103import { BusinessError } from '@ohos.base'; 4104 4105let brightness: number = 1; 4106try { 4107 let promise = windowClass.setWindowBrightness(brightness); 4108 promise.then(() => { 4109 console.info('Succeeded in setting the brightness.'); 4110 }).catch((err: BusinessError) => { 4111 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 4112 }); 4113} catch (exception) { 4114 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(exception)); 4115} 4116``` 4117 4118### setWindowFocusable<sup>9+</sup> 4119 4120setWindowFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 4121 4122设置点击时是否支持切换焦点窗口,使用callback异步回调。 4123 4124**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4125 4126**参数:** 4127 4128| 参数名 | 类型 | 必填 | 说明 | 4129| ----------- | ------------------------- | -- | ------------------------------------------------------- | 4130| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 4131| callback | AsyncCallback<void> | 是 | 回调函数。 | 4132 4133**错误码:** 4134 4135以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4136 4137| 错误码ID | 错误信息 | 4138| ------- | -------------------------------------------- | 4139| 1300002 | This window state is abnormal. | 4140| 1300003 | This window manager service works abnormally. | 4141 4142**示例:** 4143 4144```ts 4145import { BusinessError } from '@ohos.base'; 4146 4147let isFocusable: boolean = true; 4148try { 4149 windowClass.setWindowFocusable(isFocusable, (err: BusinessError) => { 4150 const errCode: number = err.code; 4151 if (errCode) { 4152 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 4153 return; 4154 } 4155 console.info('Succeeded in setting the window to be focusable.'); 4156 }); 4157} catch (exception) { 4158 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 4159} 4160``` 4161 4162### setWindowFocusable<sup>9+</sup> 4163 4164setWindowFocusable(isFocusable: boolean): Promise<void> 4165 4166设置点击时是否支持切换焦点窗口,使用Promise异步回调。 4167 4168**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4169 4170**参数:** 4171 4172| 参数名 | 类型 | 必填 | 说明 | 4173| ----------- | ------- | -- | -------------------------------------------------------- | 4174| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 4175 4176**返回值:** 4177 4178| 类型 | 说明 | 4179| ------------------- | ------------------------ | 4180| Promise<void> | 无返回结果的Promise对象。 | 4181 4182**错误码:** 4183 4184以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4185 4186| 错误码ID | 错误信息 | 4187| ------- | -------------------------------------------- | 4188| 1300002 | This window state is abnormal. | 4189| 1300003 | This window manager service works abnormally. | 4190 4191**示例:** 4192 4193```ts 4194import { BusinessError } from '@ohos.base'; 4195 4196let isFocusable: boolean = true; 4197try { 4198 let promise = windowClass.setWindowFocusable(isFocusable); 4199 promise.then(() => { 4200 console.info('Succeeded in setting the window to be focusable.'); 4201 }).catch((err: BusinessError) => { 4202 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 4203 }); 4204} catch (exception) { 4205 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(exception)); 4206} 4207``` 4208 4209### setWindowKeepScreenOn<sup>9+</sup> 4210 4211setWindowKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 4212 4213设置屏幕是否为常亮状态,使用callback异步回调。 4214 4215**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4216 4217**参数:** 4218 4219| 参数名 | 类型 | 必填 | 说明 | 4220| -------------- | ------------------------- | -- | ---------------------------------------------------- | 4221| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 4222| callback | AsyncCallback<void> | 是 | 回调函数。 | 4223 4224**错误码:** 4225 4226以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4227 4228| 错误码ID | 错误信息 | 4229| ------- | -------------------------------------------- | 4230| 1300002 | This window state is abnormal. | 4231| 1300003 | This window manager service works abnormally. | 4232 4233**示例:** 4234 4235```ts 4236import { BusinessError } from '@ohos.base'; 4237 4238let isKeepScreenOn: boolean = true; 4239try { 4240 windowClass.setWindowKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 4241 const errCode: number = err.code; 4242 if (errCode) { 4243 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 4244 return; 4245 } 4246 console.info('Succeeded in setting the screen to be always on.'); 4247 }); 4248} catch (exception) { 4249 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 4250} 4251``` 4252 4253### setWindowKeepScreenOn<sup>9+</sup> 4254 4255setWindowKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 4256 4257设置屏幕是否为常亮状态,使用Promise异步回调。 4258 4259**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4260 4261**参数:** 4262 4263| 参数名 | 类型 | 必填 | 说明 | 4264| -------------- | ------- | -- | --------------------------------------------------- | 4265| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 4266 4267**返回值:** 4268 4269| 类型 | 说明 | 4270| ------------------- | ------------------------ | 4271| Promise<void> | 无返回结果的Promise对象。 | 4272 4273**错误码:** 4274 4275以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4276 4277| 错误码ID | 错误信息 | 4278| ------- | -------------------------------------------- | 4279| 1300002 | This window state is abnormal. | 4280| 1300003 | This window manager service works abnormally. | 4281 4282**示例:** 4283 4284```ts 4285import { BusinessError } from '@ohos.base'; 4286 4287let isKeepScreenOn: boolean = true; 4288try { 4289 let promise = windowClass.setWindowKeepScreenOn(isKeepScreenOn); 4290 promise.then(() => { 4291 console.info('Succeeded in setting the screen to be always on.'); 4292 }).catch((err: BusinessError) => { 4293 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 4294 }); 4295} catch (exception) { 4296 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(exception)); 4297} 4298``` 4299 4300### setWakeUpScreen()<sup>9+</sup> 4301 4302setWakeUpScreen(wakeUp: boolean): void 4303 4304窗口唤醒屏幕。 4305 4306**系统接口:** 此接口为系统接口。 4307 4308**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4309 4310**参数:** 4311 4312| 参数名 | 类型 | 必填 | 说明 | 4313| ---------------- | ------- | ---- | ---------------------------- | 4314| wakeUp | boolean | 是 | 是否设置唤醒屏幕。true表示唤醒;false表示不唤醒。 | 4315 4316**错误码:** 4317 4318以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4319 4320| 错误码ID | 错误信息 | 4321| ------- | -------------------------------------------- | 4322| 1300002 | This window state is abnormal. | 4323| 1300003 | This window manager service works abnormally. | 4324 4325**示例:** 4326 4327```ts 4328let wakeUp: boolean = true; 4329try { 4330 windowClass.setWakeUpScreen(wakeUp); 4331} catch (exception) { 4332 console.error('Failed to wake up the screen. Cause: ' + JSON.stringify(exception)); 4333} 4334``` 4335 4336### setWindowPrivacyMode<sup>9+</sup> 4337 4338setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 4339 4340设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 4341 4342**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4343 4344**需要权限:** ohos.permission.PRIVACY_WINDOW 4345 4346**参数:** 4347 4348| 参数名 | 类型 | 必填 | 说明 | 4349| ------------- | ------------------------- | -- | ------------------------------------------------------ | 4350| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 4351| callback | AsyncCallback<void> | 是 | 回调函数。 | 4352 4353**错误码:** 4354 4355以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4356 4357| 错误码ID | 错误信息 | 4358| ------- | ------------------------------ | 4359| 1300002 | This window state is abnormal. | 4360 4361**示例:** 4362 4363```ts 4364import { BusinessError } from '@ohos.base'; 4365 4366let isPrivacyMode: boolean = true; 4367try { 4368 windowClass.setWindowPrivacyMode(isPrivacyMode, (err: BusinessError) => { 4369 const errCode: number = err.code; 4370 if (errCode) { 4371 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 4372 return; 4373 } 4374 console.info('Succeeded in setting the window to privacy mode.'); 4375 }); 4376} catch (exception) { 4377 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 4378} 4379``` 4380 4381### setWindowPrivacyMode<sup>9+</sup> 4382 4383setWindowPrivacyMode(isPrivacyMode: boolean): Promise<void> 4384 4385设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 4386 4387**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4388 4389**需要权限:** ohos.permission.PRIVACY_WINDOW 4390 4391**参数:** 4392 4393| 参数名 | 类型 | 必填 | 说明 | 4394| ------------- | ------- | -- | ----------------------------------------------------- | 4395| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 4396 4397**返回值:** 4398 4399| 类型 | 说明 | 4400| ------------------- | ------------------------ | 4401| Promise<void> | 无返回结果的Promise对象。 | 4402 4403**错误码:** 4404 4405以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4406 4407| 错误码ID | 错误信息 | 4408| ------- | ------------------------------ | 4409| 1300002 | This window state is abnormal. | 4410 4411**示例:** 4412 4413```ts 4414import { BusinessError } from '@ohos.base'; 4415 4416let isPrivacyMode: boolean = true; 4417try { 4418 let promise = windowClass.setWindowPrivacyMode(isPrivacyMode); 4419 promise.then(() => { 4420 console.info('Succeeded in setting the window to privacy mode.'); 4421 }).catch((err: BusinessError) => { 4422 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 4423 }); 4424} catch (exception) { 4425 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(exception)); 4426} 4427``` 4428 4429### setSnapshotSkip<sup>9+</sup> 4430setSnapshotSkip(isSkip: boolean): void 4431 4432截屏录屏是否忽略当前窗口。此接口一般用于禁止截屏/录屏的场景。 4433 4434**系统接口:** 此接口为系统接口。 4435 4436**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4437 4438**参数:** 4439 4440| 参数名 | 类型 | 必填 | 说明 | 4441| ------------- | ------- | ---- | -------------------- | 4442| isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。<br>true表示忽略当前窗口,false表示不忽略当前窗口。</br> | 4443 4444**错误码:** 4445 4446以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4447 4448| 错误码ID | 错误信息 | 4449| ------- | ------------------------------ | 4450| 1300002 | This window state is abnormal. | 4451 4452```ts 4453let isSkip: boolean = true; 4454try { 4455 windowClass.setSnapshotSkip(isSkip); 4456} catch (exception) { 4457 console.error('Failed to Skip. Cause: ' + JSON.stringify(exception)); 4458} 4459``` 4460 4461### setWindowTouchable<sup>9+</sup> 4462 4463setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 4464 4465设置窗口是否为可触状态,使用callback异步回调。 4466 4467**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4468 4469**参数:** 4470 4471| 参数名 | 类型 | 必填 | 说明 | 4472| ----------- | ------------------------- | -- | ----------------------------------------------- | 4473| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 4474| callback | AsyncCallback<void> | 是 | 回调函数。 | 4475 4476**错误码:** 4477 4478以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4479 4480| 错误码ID | 错误信息 | 4481| ------- | -------------------------------------------- | 4482| 1300002 | This window state is abnormal. | 4483| 1300003 | This window manager service works abnormally. | 4484 4485**示例:** 4486 4487```ts 4488import { BusinessError } from '@ohos.base'; 4489 4490let isTouchable = true; 4491try { 4492 windowClass.setWindowTouchable(isTouchable, (err: BusinessError) => { 4493 const errCode: number = err.code; 4494 if (errCode) { 4495 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 4496 return; 4497 } 4498 console.info('Succeeded in setting the window to be touchable.'); 4499 }); 4500} catch (exception) { 4501 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 4502} 4503``` 4504 4505### setWindowTouchable<sup>9+</sup> 4506 4507setWindowTouchable(isTouchable: boolean): Promise<void> 4508 4509设置窗口是否为可触状态,使用Promise异步回调。 4510 4511**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4512 4513**参数:** 4514 4515| 参数名 | 类型 | 必填 | 说明 | 4516| ----------- | ------- | -- | ----------------------------------------------- | 4517| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 4518 4519**返回值:** 4520 4521| 类型 | 说明 | 4522| ------------------- | ------------------------- | 4523| Promise<void> | 无返回结果的Promise对象。 | 4524 4525**错误码:** 4526 4527以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4528 4529| 错误码ID | 错误信息 | 4530| ------- | -------------------------------------------- | 4531| 1300002 | This window state is abnormal. | 4532| 1300003 | This window manager service works abnormally. | 4533 4534**示例:** 4535 4536```ts 4537import { BusinessError } from '@ohos.base'; 4538 4539let isTouchable: boolean = true; 4540try { 4541 let promise = windowClass.setWindowTouchable(isTouchable); 4542 promise.then(() => { 4543 console.info('Succeeded in setting the window to be touchable.'); 4544 }).catch((err: BusinessError) => { 4545 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 4546 }); 4547} catch (exception) { 4548 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(exception)); 4549} 4550``` 4551 4552### setForbidSplitMove<sup>9+</sup> 4553 4554setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void 4555 4556设置窗口在分屏模式下是否被禁止移动,使用callback异步回调。 4557 4558**系统接口:** 此接口为系统接口。 4559 4560**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4561 4562**参数:** 4563 4564| 参数名 | 类型 | 必填 | 说明 | 4565| ----------- | ------------------------- | ---- | -------------------- | 4566| isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | 4567| callback | AsyncCallback<void> | 是 | 回调函数。 | 4568 4569**错误码:** 4570 4571以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4572 4573| 错误码ID | 错误信息 | 4574| ------- | -------------------------------------------- | 4575| 1300002 | This window state is abnormal. | 4576| 1300003 | This window manager service works abnormally. | 4577 4578**示例:** 4579 4580```ts 4581import { BusinessError } from '@ohos.base'; 4582 4583let isForbidSplitMove: boolean = true; 4584try { 4585 windowClass.setForbidSplitMove(isForbidSplitMove, (err: BusinessError) => { 4586 const errCode: number = err.code; 4587 if (errCode) { 4588 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(err)); 4589 return; 4590 } 4591 console.info('Succeeded in forbidding window moving in split screen mode.'); 4592 }); 4593} catch (exception) { 4594 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception)); 4595} 4596``` 4597 4598### setForbidSplitMove<sup>9+</sup> 4599 4600setForbidSplitMove(isForbidSplitMove: boolean): Promise<void> 4601 4602设置窗口在分屏模式下是否被禁止移动,使用Promise异步回调。 4603 4604**系统接口:** 此接口为系统接口。 4605 4606**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4607 4608**参数:** 4609 4610| 参数名 | 类型 | 必填 | 说明 | 4611| ----------- | ------- | ---- | -------------------- | 4612| isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | 4613 4614**返回值:** 4615 4616| 类型 | 说明 | 4617| ------------------- | ------------------------- | 4618| Promise<void> | 无返回结果的Promise对象。 | 4619 4620**错误码:** 4621 4622以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4623 4624| 错误码ID | 错误信息 | 4625| ------- | -------------------------------------------- | 4626| 1300002 | This window state is abnormal. | 4627| 1300003 | This window manager service works abnormally. | 4628 4629**示例:** 4630 4631```ts 4632import { BusinessError } from '@ohos.base'; 4633 4634let isForbidSplitMove: boolean = true; 4635try { 4636 let promise = windowClass.setForbidSplitMove(isForbidSplitMove); 4637 promise.then(() => { 4638 console.info('Succeeded in forbidding window moving in split screen mode.'); 4639 }).catch((err: BusinessError) => { 4640 console.error('Failed to forbid window moving in split screen mode. Cause: ' + JSON.stringify(err)); 4641 }); 4642} catch (exception) { 4643 console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception)); 4644} 4645``` 4646 4647### snapshot<sup>9+</sup> 4648 4649snapshot(callback: AsyncCallback<image.PixelMap>): void 4650 4651获取窗口截图,使用callback异步回调。 4652 4653**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4654 4655**参数:** 4656 4657| 参数名 | 类型 | 必填 | 说明 | 4658| ----------- | ------------------------- | ---- | -------------------- | 4659| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | 是 | 回调函数。 | 4660 4661**错误码:** 4662 4663以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4664 4665| 错误码ID | 错误信息 | 4666| ------- | ------------------------------ | 4667| 1300002 | This window state is abnormal. | 4668 4669**示例:** 4670 4671```ts 4672import { BusinessError } from '@ohos.base'; 4673import image from '@ohos.multimedia.image'; 4674 4675windowClass.snapshot((err: BusinessError, pixelMap: image.PixelMap) => { 4676 const errCode: number = err.code; 4677 if (errCode) { 4678 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 4679 return; 4680 } 4681 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 4682 pixelMap.release(); // PixelMap使用完后及时释放内存 4683}); 4684``` 4685 4686### snapshot<sup>9+</sup> 4687 4688snapshot(): Promise<image.PixelMap> 4689 4690获取窗口截图,使用Promise异步回调。 4691 4692**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4693 4694**返回值:** 4695 4696| 类型 | 说明 | 4697| ------------------- | ------------------------- | 4698| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise对象。返回当前窗口截图。 | 4699 4700**错误码:** 4701 4702以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4703 4704| 错误码ID | 错误信息 | 4705| ------- | ------------------------------ | 4706| 1300002 | This window state is abnormal. | 4707 4708**示例:** 4709 4710```ts 4711import { BusinessError } from '@ohos.base'; 4712import image from '@ohos.multimedia.image'; 4713 4714let promise = windowClass.snapshot(); 4715promise.then((pixelMap: image.PixelMap) => { 4716 console.info('Succeeded in snapshotting window. Pixel bytes number: ' + pixelMap.getPixelBytesNumber()); 4717 pixelMap.release(); // PixelMap使用完后及时释放内存 4718}).catch((err: BusinessError) => { 4719 console.error('Failed to snapshot window. Cause:' + JSON.stringify(err)); 4720}); 4721``` 4722 4723### opacity<sup>9+</sup> 4724 4725opacity(opacity: number): void 4726 4727设置窗口不透明度。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 4728 4729**系统接口:** 此接口为系统接口。 4730 4731**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4732 4733**参数:** 4734 4735| 参数名 | 类型 | 必填 | 说明 | 4736| ------- | ------ | ---- |----------------------------------------------------| 4737| opacity | number | 是 | 不透明度。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示完全透明,1.0表示完全不透明。 | 4738 4739**错误码:** 4740 4741以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4742 4743| 错误码ID | 错误信息 | 4744| ------- | ------------------------------ | 4745| 1300002 | This window state is abnormal. | 4746| 1300004 | Unauthorized operation. | 4747 4748**示例:** 4749 4750```ts 4751try { 4752 windowClass.opacity(0.5); 4753} catch (exception) { 4754 console.error('Failed to opacity. Cause: ' + JSON.stringify(exception)); 4755} 4756``` 4757 4758### scale<sup>9+</sup> 4759 4760scale(scaleOptions: ScaleOptions): void 4761 4762设置窗口缩放参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 4763 4764**系统接口:** 此接口为系统接口。 4765 4766**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4767 4768**参数:** 4769 4770| 参数名 | 类型 | 必填 | 说明 | 4771| ------------ | ------------------------------ | ---- | ---------- | 4772| scaleOptions | [ScaleOptions](#scaleoptions9) | 是 | 缩放参数。 | 4773 4774**错误码:** 4775 4776以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4777 4778| 错误码ID | 错误信息 | 4779| ------- | ------------------------------ | 4780| 1300002 | This window state is abnormal. | 4781| 1300004 | Unauthorized operation. | 4782 4783**示例:** 4784 4785```ts 4786let obj: window.ScaleOptions = { 4787 x: 2.0, 4788 y: 1.0, 4789 pivotX: 0.5, 4790 pivotY: 0.5 4791}; 4792try { 4793 windowClass.scale(obj); 4794} catch (exception) { 4795 console.error('Failed to scale. Cause: ' + JSON.stringify(exception)); 4796} 4797``` 4798 4799### rotate<sup>9+</sup> 4800 4801rotate(rotateOptions: RotateOptions): void 4802 4803设置窗口旋转参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 4804 4805**系统接口:** 此接口为系统接口。 4806 4807**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4808 4809**参数:** 4810 4811| 参数名 | 类型 | 必填 | 说明 | 4812| ------------- | -------------------------------- | ---- | ---------- | 4813| rotateOptions | [RotateOptions](#rotateoptions9) | 是 | 旋转参数。 | 4814 4815**错误码:** 4816 4817以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4818 4819| 错误码ID | 错误信息 | 4820| ------- | ------------------------------ | 4821| 1300002 | This window state is abnormal. | 4822| 1300004 | Unauthorized operation. | 4823 4824**示例:** 4825 4826```ts 4827let obj: window.RotateOptions = { 4828 x: 1.0, 4829 y: 1.0, 4830 z: 45.0, 4831 pivotX: 0.5, 4832 pivotY: 0.5 4833}; 4834try { 4835 windowClass.rotate(obj); 4836} catch (exception) { 4837 console.error('Failed to rotate. Cause: ' + JSON.stringify(exception)); 4838} 4839``` 4840 4841### translate<sup>9+</sup> 4842 4843translate(translateOptions: TranslateOptions): void 4844 4845设置窗口平移参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 4846 4847**系统接口:** 此接口为系统接口。 4848 4849**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4850 4851**参数:** 4852 4853| 参数名 | 类型 | 必填 | 说明 | 4854| ---------------- | -------------------------------------- | ---- | -------------------- | 4855| translateOptions | [TranslateOptions](#translateoptions9) | 是 | 平移参数,单位为px。 | 4856 4857**错误码:** 4858 4859以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4860 4861| 错误码ID | 错误信息 | 4862| ------- | ------------------------------ | 4863| 1300002 | This window state is abnormal. | 4864| 1300004 | Unauthorized operation. | 4865 4866**示例:** 4867 4868```ts 4869let obj: window.TranslateOptions = { 4870 x: 100.0, 4871 y: 0.0, 4872 z: 0.0 4873}; 4874try { 4875 windowClass.translate(obj); 4876} catch (exception) { 4877 console.error('Failed to translate. Cause: ' + JSON.stringify(exception)); 4878} 4879``` 4880 4881### getTransitionController<sup>9+</sup> 4882 4883getTransitionController(): TransitionController 4884 4885获取窗口属性转换控制器。 4886 4887**系统接口:** 此接口为系统接口。 4888 4889**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4890 4891**返回值:** 4892 4893| 类型 | 说明 | 4894| ---------------------------------------------- | ---------------- | 4895| [TransitionController](#transitioncontroller9) | 属性转换控制器。 | 4896 4897**错误码:** 4898 4899以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4900 4901| 错误码ID | 错误信息 | 4902| ------- | ------------------------------ | 4903| 1300002 | This window state is abnormal. | 4904| 1300004 | Unauthorized operation. | 4905 4906**示例:** 4907 4908```ts 4909let controller = windowClass.getTransitionController(); // 获取属性转换控制器 4910``` 4911 4912### setBlur<sup>9+</sup> 4913 4914setBlur(radius: number): void 4915 4916设置窗口模糊。 4917 4918**系统接口:** 此接口为系统接口。 4919 4920**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4921 4922**参数:** 4923 4924| 参数名 | 类型 | 必填 | 说明 | 4925| ------ | ------ | ---- |--------------------------------------------------| 4926| radius | number | 是 | 表示窗口模糊的半径值。该参数为浮点数,单位为px,取值范围为[0, +∞),取值为0.0时表示关闭窗口模糊。 | 4927 4928**错误码:** 4929 4930以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4931 4932| 错误码ID | 错误信息 | 4933| ------- | ------------------------------ | 4934| 1300002 | This window state is abnormal. | 4935| 1300004 | Unauthorized operation. | 4936 4937**示例:** 4938 4939```ts 4940try { 4941 windowClass.setBlur(4.0); 4942} catch (exception) { 4943 console.error('Failed to set blur. Cause: ' + JSON.stringify(exception)); 4944} 4945``` 4946 4947### setBackdropBlur<sup>9+</sup> 4948 4949setBackdropBlur(radius: number): void 4950 4951设置窗口背景模糊。 4952 4953**系统接口:** 此接口为系统接口。 4954 4955**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4956 4957**参数:** 4958 4959| 参数名 | 类型 | 必填 | 说明 | 4960| ------ | ------ | ---- |-------------------------------------------------------| 4961| radius | number | 是 | 表示窗口背景模糊的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0表示关闭窗口背景模糊。 | 4962 4963**错误码:** 4964 4965以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 4966 4967| 错误码ID | 错误信息 | 4968| ------- | ------------------------------ | 4969| 1300002 | This window state is abnormal. | 4970| 1300004 | Unauthorized operation. | 4971 4972**示例:** 4973 4974```ts 4975try { 4976 windowClass.setBackdropBlur(4.0); 4977} catch (exception) { 4978 console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception)); 4979} 4980``` 4981 4982### setBackdropBlurStyle<sup>9+</sup> 4983 4984setBackdropBlurStyle(blurStyle: BlurStyle): void 4985 4986设置窗口背景模糊类型。 4987 4988**系统接口:** 此接口为系统接口。 4989 4990**系统能力:** SystemCapability.WindowManager.WindowManager.Core 4991 4992**参数:** 4993 4994| 参数名 | 类型 | 必填 | 说明 | 4995| --------- | --------- | ---- | ---------------------- | 4996| blurStyle | [BlurStyle](#blurstyle9) | 是 | 表示窗口背景模糊类型。 | 4997 4998**错误码:** 4999 5000以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5001 5002| 错误码ID | 错误信息 | 5003| ------- | ------------------------------ | 5004| 1300002 | This window state is abnormal. | 5005| 1300004 | Unauthorized operation. | 5006 5007**示例:** 5008 5009```ts 5010try { 5011 windowClass.setBackdropBlurStyle(window.BlurStyle.THIN); 5012} catch (exception) { 5013 console.error('Failed to set backdrop blur style. Cause: ' + JSON.stringify(exception)); 5014} 5015``` 5016 5017### setShadow<sup>9+</sup> 5018 5019setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void 5020 5021设置窗口边缘阴影。 5022 5023**系统接口:** 此接口为系统接口。 5024 5025**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5026 5027**参数:** 5028 5029| 参数名 | 类型 | 必填 | 说明 | 5030| ------- | ------ | ---- |-------------------------------------------------------------| 5031| radius | number | 是 | 表示窗口边缘阴影的模糊半径。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示关闭窗口边缘阴影。 | 5032| color | string | 否 | 表示窗口边缘阴影的颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 5033| offsetX | number | 否 | 表示窗口边缘阴影的X轴的偏移量。该参数为浮点数,单位为px。 | 5034| offsetY | number | 否 | 表示窗口边缘阴影的Y轴的偏移量。该参数为浮点数,单位为px。 | 5035 5036**错误码:** 5037 5038以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5039 5040| 错误码ID | 错误信息 | 5041| ------- | ------------------------------ | 5042| 1300002 | This window state is abnormal. | 5043| 1300004 | Unauthorized operation. | 5044 5045**示例:** 5046 5047```ts 5048try { 5049 windowClass.setShadow(4.0, '#FF00FF00', 2, 3); 5050} catch (exception) { 5051 console.error('Failed to set shadow. Cause: ' + JSON.stringify(exception)); 5052} 5053``` 5054 5055### setCornerRadius<sup>9+</sup> 5056 5057setCornerRadius(cornerRadius: number): void 5058 5059设置窗口圆角半径。 5060 5061**系统接口:** 此接口为系统接口。 5062 5063**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5064 5065**参数:** 5066 5067| 参数名 | 类型 | 必填 | 说明 | 5068| ----------- | ------- | ---- |----------------------------------------------------| 5069| radius | number | 是 | 表示窗口圆角的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。 | 5070 5071**错误码:** 5072 5073以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5074 5075| 错误码ID | 错误信息 | 5076| ------- | ------------------------------ | 5077| 1300002 | This window state is abnormal. | 5078| 1300004 | Unauthorized operation. | 5079 5080**示例:** 5081 5082```ts 5083try { 5084 windowClass.setCornerRadius(4.0); 5085} catch (exception) { 5086 console.error('Failed to set corner radius. Cause: ' + JSON.stringify(exception)); 5087} 5088``` 5089 5090### raiseToAppTop<sup>10+</sup> 5091 5092raiseToAppTop(callback: AsyncCallback<void>): void 5093 5094提升应用子窗口到应用顶层。使用callback异步回调。 5095 5096**系统接口:** 此接口为系统接口。 5097 5098**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5099 5100**参数:** 5101 5102| 参数名 | 类型 | 必填 | 说明 | 5103| -------- | ------------------------- | ---- | ---------- | 5104| callback | AsyncCallback<void> | 是 | 回调函数。 | 5105 5106**错误码:** 5107 5108以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5109 5110| 错误码ID | 错误信息 | 5111| ------- | ------------------------------ | 5112| 1300002 | This window state is abnormal. | 5113| 1300003 | This window manager service works abnormally. | 5114| 1300004 | Unauthorized operation. | 5115| 1300009 | The parent window is invalid. | 5116 5117**示例:** 5118 5119```ts 5120import { BusinessError } from '@ohos.base'; 5121 5122windowClass.raiseToAppTop((err: BusinessError) => { 5123 const errCode: number = err.code; 5124 if (errCode) { 5125 console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err)); 5126 return; 5127 } 5128 console.info('Succeeded in raising the window to app top.'); 5129}); 5130``` 5131 5132### raiseToAppTop<sup>10+</sup> 5133 5134raiseToAppTop(): Promise<void> 5135 5136提升应用子窗口到应用顶层。使用Promise异步回调。 5137 5138**系统接口:** 此接口为系统接口。 5139 5140**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5141 5142**返回值:** 5143 5144| 类型 | 说明 | 5145| ------------------- | ------------------------- | 5146| Promise<void> | 无返回结果的Promise对象。 | 5147 5148**错误码:** 5149 5150以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5151 5152| 错误码ID | 错误信息 | 5153| ------- | ------------------------------ | 5154| 1300002 | This window state is abnormal. | 5155| 1300003 | This window manager service works abnormally. | 5156| 1300004 | Unauthorized operation. | 5157| 1300009 | The parent window is invalid. | 5158 5159**示例:** 5160 5161```ts 5162import { BusinessError } from '@ohos.base'; 5163 5164let promise = windowClass.raiseToAppTop(); 5165promise.then(() => { 5166 console.info('Succeeded in raising the window to app top.'); 5167}).catch((err: BusinessError) => { 5168 console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err)); 5169}); 5170``` 5171 5172### setAspectRatio<sup>10+</sup> 5173 5174setAspectRatio(ratio: number): Promise<void> 5175 5176设置窗口内容布局的比例,使用Promise异步回调。 5177 5178仅应用主窗口支持此接口功能,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 5179 5180**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5181 5182**参数:** 5183 5184| 参数名 | 类型 | 必填 | 说明 | 5185| ------------------ | ------- | ---- |-------------------------------------------| 5186| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,取值范围为(0.0, +∞)。 | 5187 5188**返回值:** 5189 5190| 类型 | 说明 | 5191| ------------------- | ------------------------- | 5192| Promise<void> | 无返回结果的Promise对象。 | 5193 5194**错误码:** 5195 5196以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5197 5198| 错误码ID | 错误信息 | 5199| ------- | -------------------------------------------- | 5200| 1300002 | This window state is abnormal. | 5201| 1300004 | Unauthorized operation. | 5202 5203**示例:** 5204 5205```ts 5206import { BusinessError } from '@ohos.base'; 5207 5208try { 5209 let ratio = 1.0; 5210 let promise = windowClass.setAspectRatio(ratio); 5211 promise.then(() => { 5212 console.info('Succeeded in setting aspect ratio of window.'); 5213 }).catch((err: BusinessError) => { 5214 console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err)); 5215 }); 5216} catch (exception) { 5217 console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5218} 5219``` 5220 5221### setAspectRatio<sup>10+</sup> 5222 5223setAspectRatio(ratio: number, callback: AsyncCallback<void>): void 5224 5225设置窗口内容布局的比例,使用callback异步回调。 5226 5227仅应用主窗口支持此接口功能,比例参数将持久化保存,关闭应用或重启设备设置的比例仍然生效。 5228 5229**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5230 5231**参数:** 5232 5233| 参数名 | 类型 | 必填 | 说明 | 5234| ------------------ | ------- | ---- |--------------------------------------------| 5235| ratio | number | 是 | 除边框装饰之外的窗口内容布局的宽高比。该参数为浮点数,取值范围为(0.0, +∞)。 | 5236| callback | AsyncCallback<void> | 是 | 回调函数。 | 5237 5238**错误码:** 5239 5240以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5241 5242| 错误码ID | 错误信息 | 5243| ------- | -------------------------------------------- | 5244| 1300002 | This window state is abnormal. | 5245| 1300004 | Unauthorized operation. | 5246 5247**示例:** 5248 5249```ts 5250import { BusinessError } from '@ohos.base'; 5251 5252try { 5253 let ratio = 1.0; 5254 windowClass.setAspectRatio(ratio, (err: BusinessError) => { 5255 const errCode: number = err.code; 5256 if (errCode) { 5257 console.error('Failed to set the aspect ratio of window. Cause:' + JSON.stringify(err)); 5258 return; 5259 } 5260 console.info('Succeeded in setting the aspect ratio of window.'); 5261 }); 5262} catch (exception) { 5263 console.error('Failed to set the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5264} 5265``` 5266 5267### resetAspectRatio<sup>10+</sup> 5268 5269resetAspectRatio(): Promise<void> 5270 5271取消设置窗口内容布局的比例,使用Promise异步回调。 5272 5273仅应用主窗口支持此接口功能,调用后将清除持久化储存的比例信息。 5274 5275**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5276 5277**返回值:** 5278 5279| 类型 | 说明 | 5280| ------------------- | ------------------------- | 5281| Promise<void> | 无返回结果的Promise对象。 | 5282 5283**错误码:** 5284 5285以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5286 5287| 错误码ID | 错误信息 | 5288| ------- | -------------------------------------------- | 5289| 1300002 | This window state is abnormal. | 5290| 1300004 | Unauthorized operation. | 5291 5292**示例:** 5293 5294```ts 5295import { BusinessError } from '@ohos.base'; 5296 5297try { 5298 let promise = windowClass.resetAspectRatio(); 5299 promise.then(() => { 5300 console.info('Succeeded in resetting aspect ratio of window.'); 5301 }).catch((err: BusinessError) => { 5302 console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err)); 5303 }); 5304} catch (exception) { 5305 console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5306} 5307``` 5308 5309### resetAspectRatio<sup>10+</sup> 5310 5311resetAspectRatio(callback: AsyncCallback<void>): void 5312 5313取消设置窗口内容布局的比例,使用callback异步回调。 5314 5315仅应用主窗口支持此接口功能,调用后将清除持久化储存的比例信息。 5316 5317**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5318 5319**参数:** 5320 5321| 参数名 | 类型 | 必填 | 说明 | 5322| ------------------ | ------- | ---- | ------------------------------------------------------------ | 5323| callback | AsyncCallback<void> | 是 | 回调函数。 | 5324 5325**错误码:** 5326 5327以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5328 5329| 错误码ID | 错误信息 | 5330| ------- | -------------------------------------------- | 5331| 1300002 | This window state is abnormal. | 5332| 1300004 | Unauthorized operation. | 5333 5334**示例:** 5335 5336```ts 5337import { BusinessError } from '@ohos.base'; 5338 5339try { 5340 windowClass.resetAspectRatio((err: BusinessError) => { 5341 const errCode: number = err.code; 5342 if (errCode) { 5343 console.error('Failed to reset the aspect ratio of window. Cause:' + JSON.stringify(err)); 5344 return; 5345 } 5346 console.info('Succeeded in resetting aspect ratio of window.'); 5347 }); 5348} catch (exception) { 5349 console.error('Failed to reset the aspect ratio of window. Cause: ' + JSON.stringify(exception)); 5350} 5351``` 5352 5353### setWaterMarkFlag<sup>10+</sup> 5354 5355setWaterMarkFlag(enable: boolean): Promise<void> 5356 5357为当前窗口添加或删除安全水印标志,使用Promise异步回调。 5358 5359**系统接口:** 此接口为系统接口。 5360 5361**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5362 5363**参数:** 5364 5365| 参数名 | 类型 | 必填 | 说明 | 5366| ------ | ------- | --- | ------------------------------------------------ | 5367| enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 | 5368 5369**返回值:** 5370 5371| 类型 | 说明 | 5372| ------------------- | ------------------------- | 5373| Promise<void> | 无返回结果的Promise对象。 | 5374 5375**错误码:** 5376 5377以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5378 5379| 错误码ID | 错误信息 | 5380| ------- | ---------------------------------------------- | 5381| 1300002 | This window state is abnormal. | 5382| 1300003 | This window manager service works abnormally. | 5383| 1300008 | The operation is on invalid display. | 5384 5385**示例:** 5386 5387```ts 5388import { BusinessError } from '@ohos.base'; 5389 5390try { 5391 let enable = true; 5392 let promise = windowClass.setWaterMarkFlag(enable); 5393 promise.then(() => { 5394 console.info('Succeeded in setting water mark flag of window.'); 5395 }).catch((err: BusinessError) => { 5396 console.error('Failed to set water mark flag of window. Cause:' + JSON.stringify(err)); 5397 }); 5398} catch (exception) { 5399 console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception)); 5400} 5401``` 5402 5403### setWaterMarkFlag<sup>10+</sup> 5404 5405setWaterMarkFlag(enable: boolean, callback: AsyncCallback<void>): void 5406 5407为当前窗口添加或删除安全水印标志,使用callback异步回调。 5408 5409**系统接口:** 此接口为系统接口。 5410 5411**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5412 5413**参数:** 5414 5415| 参数名 | 类型 | 必填 | 说明 | 5416| -------- | ------------------------- | --- | ----------------------------------------------- | 5417| enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 | 5418| callback | AsyncCallback<void> | 是 | 回调函数。 | 5419 5420**错误码:** 5421 5422以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5423 5424| 错误码ID | 错误信息 | 5425| ------- | ---------------------------------------------- | 5426| 1300002 | This window state is abnormal. | 5427| 1300003 | This window manager service works abnormally. | 5428| 1300008 | The operation is on invalid display. | 5429 5430**示例:** 5431 5432```ts 5433import { BusinessError } from '@ohos.base'; 5434 5435try { 5436 let enable: boolean = true; 5437 windowClass.setWaterMarkFlag(enable, (err: BusinessError) => { 5438 const errCode: number = err.code; 5439 if (errCode) { 5440 console.error('Failed to set water mark flag of window. Cause:' + JSON.stringify(err)); 5441 return; 5442 } 5443 console.info('Succeeded in setting water mark flag of window.'); 5444 }); 5445} catch (exception) { 5446 console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception)); 5447} 5448``` 5449 5450### raiseAboveTarget<sup>10+</sup> 5451 5452raiseAboveTarget(windowId: number, callback: AsyncCallback<void>): void 5453 5454将同一个主窗口下的子窗口提升到目标子窗口之上。使用callback异步回调。 5455 5456**系统接口:** 此接口为系统接口。 5457 5458**系统能力:** SystemCapability.Window.SessionManager 5459 5460**参数:** 5461 5462| 参数名 | 类型 | 必填 | 说明 | 5463| -------- | ------------------------- | ---- | ---------- | 5464| windowId | number | 是 | 目标子窗口的id,通过[getWindowProperties](#getwindowproperties9)接口获取到[properties](#windowproperties)后,再通过properties.id获取 | 5465| callback | AsyncCallback<void> | 是 | 回调函数。 | 5466 5467**错误码:** 5468 5469以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5470 5471| 错误码ID | 错误信息 | 5472| ------- | ---------------------------------------------- | 5473| 1300002 | This window state is abnormal. | 5474| 1300003 | This window manager service works abnormally. | 5475| 1300004 | Unauthorized operation. | 5476| 1300009 | The parent window is invalid. | 5477 5478**示例:** 5479 5480```ts 5481// windowClass的获取需放在targetWindow之上 5482let targetWindow: window.Window = windowClass; 5483let properties = targetWindow.getWindowProperties(); 5484let targetId = properties.id; 5485windowClass.raiseAboveTarget(targetId, (err) => { 5486 if (err.code) { 5487 console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err)); 5488 return; 5489 } 5490 console.info('Succeeded in raising the subWindow to target subWindow top.'); 5491}); 5492``` 5493 5494### raiseAboveTarget<sup>10+</sup> 5495 5496raiseAboveTarget(windowId: number): Promise<void> 5497 5498将同一个主窗下的子窗口提升到目标子窗口之上。使用Promise异步回调。 5499 5500**系统接口:** 此接口为系统接口。 5501 5502**系统能力:** SystemCapability.Window.SessionManager 5503 5504**参数:** 5505 5506| 参数名 | 类型 | 必填 | 说明 | 5507| -------- | ------------------------- | ---- | ---------- | 5508| windowId | number | 是 | 目标子窗口的id,通过[getWindowProperties](#getwindowproperties9)接口获取到[properties](#windowproperties)后,再通过properties.id获取 | 5509 5510**返回值:** 5511 5512| 类型 | 说明 | 5513| ------------------- | ------------------------- | 5514| Promise<void> | 无返回结果的Promise对象。 | 5515 5516**错误码:** 5517 5518以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5519 5520| 错误码ID | 错误信息 | 5521| ------- | ------------------------------ | 5522| 1300002 | This window state is abnormal. | 5523| 1300003 | This window manager service works abnormally. | 5524| 1300004 | Unauthorized operation. | 5525| 1300009 | The parent window is invalid. | 5526 5527**示例:** 5528 5529```ts 5530// windowClass的获取需放在targetWindow之上 5531let targetWindow: window.Window = windowClass; 5532let properties = targetWindow.getWindowProperties(); 5533let targetId = properties.id; 5534let promise = windowClass.raiseAboveTarget(targetId); 5535promise.then(()=> { 5536 console.info('Succeeded in raising the subWindow to target subWindow top.'); 5537}).catch((err)=>{ 5538 console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err)); 5539}); 5540``` 5541 5542### setRaiseByClickEnabled<sup>10+</sup> 5543 5544setRaiseByClickEnabled(enable: boolean, callback: AsyncCallback<void>): void 5545 5546禁止/使能子窗口点击抬升功能。使用callback异步回调。 5547 5548通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。 5549 5550**系统接口:** 此接口为系统接口。 5551 5552**系统能力:** SystemCapability.Window.SessionManager 5553 5554**参数:** 5555 5556| 参数名 | 类型 | 必填 | 说明 | 5557| -------- | ------------------------- | ---- | ---------- | 5558| enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | 5559| callback | AsyncCallback<void> | 是 | 回调函数。 | 5560 5561**错误码:** 5562 5563以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5564 5565| 错误码ID | 错误信息 | 5566| ------- | ------------------------------ | 5567| 1300002 | This window state is abnormal. | 5568| 1300003 | This window manager service works abnormally. | 5569| 1300004 | Unauthorized operation. | 5570| 1300009 | The parent window is invalid. | 5571 5572**示例:** 5573 5574```ts 5575let enabled = false; 5576windowClass.setRaiseByClickEnabled(enabled, (err) => { 5577 if (err.code) { 5578 console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err)); 5579 return; 5580 } 5581 console.info('Succeeded in disabling the raise-by-click function.'); 5582}); 5583``` 5584 5585### setRaiseByClickEnabled<sup>10+</sup> 5586 5587setRaiseByClickEnabled(enable: boolean): Promise<void> 5588 5589禁止/使能子窗点击抬升功能。使用Promise异步回调。 5590 5591通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。 5592 5593**系统接口:** 此接口为系统接口。 5594 5595**系统能力:** SystemCapability.Window.SessionManager 5596 5597**参数:** 5598 5599| 参数名 | 类型 | 必填 | 说明 | 5600| -------- | ------------------------- | ---- | ---------- | 5601| enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | 5602 5603**返回值:** 5604 5605| 类型 | 说明 | 5606| ------------------- | ------------------------- | 5607| Promise<void> | 无返回结果的Promise对象。 | 5608 5609**错误码:** 5610 5611以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5612 5613| 错误码ID | 错误信息 | 5614| ------- | ------------------------------ | 5615| 1300002 | This window state is abnormal. | 5616| 1300003 | This window manager service works abnormally. | 5617| 1300004 | Unauthorized operation. | 5618| 1300009 | The parent window is invalid. | 5619 5620**示例:** 5621 5622```ts 5623let enabled = false; 5624let promise = windowClass.setRaiseByClickEnabled(enabled); 5625promise.then(()=> { 5626 console.info('Succeeded in disabling the raise-by-click function.'); 5627}).catch((err)=>{ 5628 console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err)); 5629}); 5630``` 5631 5632### minimize<sup>10+</sup> 5633 5634minimize(callback: AsyncCallback<void>): void 5635 5636最小化主窗口。使用callback异步回调。 5637 5638**系统接口:** 此接口为系统接口。 5639 5640**系统能力:** SystemCapability.Window.SessionManager 5641 5642**参数:** 5643 5644| 参数名 | 类型 | 必填 | 说明 | 5645| -------- | ------------------------- | ---- | ---------- | 5646| callback | AsyncCallback<void> | 是 | 回调函数。 | 5647 5648**错误码:** 5649 5650以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5651 5652| 错误码ID | 错误信息 | 5653| ------- | ------------------------------ | 5654| 1300002 | This window state is abnormal. | 5655| 1300003 | This window manager service works abnormally. | 5656 5657**示例:** 5658 5659```ts 5660import UIAbility from '@ohos.app.ability.UIAbility'; 5661 5662export default class EntryAbility extends UIAbility { 5663 onWindowStageCreate(windowStage) { 5664 // 为主窗口加载对应的目标页面。 5665 windowStage.loadContent("pages/page2", (err) => { 5666 if (err.code) { 5667 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5668 return; 5669 } 5670 console.info('Succeeded in loading the content.'); 5671 }); 5672 // 获取应用主窗口。 5673 let mainWindow: window.Window | undefined = undefined; 5674 5675 windowStage.getMainWindow((err, data) => { 5676 if (err.code) { 5677 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5678 return; 5679 } 5680 mainWindow = data; 5681 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5682 // 调用minimize接口。 5683 mainWindow.minimize((err) => { 5684 if (err.code) { 5685 console.error('Failed to minimize the app main window. Cause: ' + JSON.stringify(err)); 5686 return; 5687 } 5688 console.info('Successfully minimized app main window.'); 5689 }); 5690 }) 5691 } 5692}; 5693``` 5694 5695### minimize<sup>10+</sup> 5696 5697minimize(): Promise<void> 5698 5699最小化主窗口。使用Promise异步回调。 5700 5701**系统接口:** 此接口为系统接口。 5702 5703**系统能力:** SystemCapability.Window.SessionManager 5704 5705**返回值:** 5706 5707| 类型 | 说明 | 5708| ------------------- | ------------------------- | 5709| Promise<void> | 无返回结果的Promise对象。 | 5710 5711**错误码:** 5712 5713以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5714 5715| 错误码ID | 错误信息 | 5716| ------- | ------------------------------ | 5717| 1300002 | This window state is abnormal. | 5718| 1300003 | This window manager service works abnormally. | 5719 5720**示例:** 5721 5722```ts 5723import UIAbility from '@ohos.app.ability.UIAbility'; 5724 5725export default class EntryAbility extends UIAbility { 5726 onWindowStageCreate(windowStage) { 5727 // 为主窗口加载对应的目标页面。 5728 windowStage.loadContent("pages/page2", (err) => { 5729 if (err.code) { 5730 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5731 return; 5732 } 5733 console.info('Succeeded in loading the content.'); 5734 }); 5735 // 获取应用主窗口。 5736 let mainWindow: window.Window | undefined = undefined; 5737 5738 windowStage.getMainWindow((err, data) => { 5739 if (err.code) { 5740 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5741 return; 5742 } 5743 mainWindow = data; 5744 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5745 // 获取minimize接口的promise对象。 5746 let promise = mainWindow.minimize(); 5747 promise.then(()=> { 5748 console.info('Successfully minimized app main window.'); 5749 }).catch((err)=>{ 5750 console.error('Failed to minimize the app main window. Cause: ' + JSON.stringify(err)); 5751 }); 5752 }) 5753 } 5754}; 5755``` 5756 5757### setResizeByDragEnabled<sup>10+</sup> 5758 5759setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void 5760 5761禁止/使能通过拖拽方式缩放主窗口的功能。使用callback异步回调。 5762 5763**系统接口:** 此接口为系统接口。 5764 5765**系统能力:** SystemCapability.Window.SessionManager 5766 5767**参数:** 5768 5769| 参数名 | 类型 | 必填 | 说明 | 5770| -------- | ------------------------- | ---- | ---------- | 5771| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 5772| callback | AsyncCallback<void> | 是 | 回调函数。 | 5773 5774**错误码:** 5775 5776以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5777 5778| 错误码ID | 错误信息 | 5779| ------- | ------------------------------ | 5780| 1300002 | This window state is abnormal. | 5781| 1300003 | This window manager service works abnormally. | 5782| 1300004 | Unauthorized operation. | 5783 5784**示例:** 5785 5786```ts 5787import UIAbility from '@ohos.app.ability.UIAbility'; 5788 5789export default class EntryAbility extends UIAbility { 5790 onWindowStageCreate(windowStage) { 5791 // 为主窗口加载对应的目标页面。 5792 windowStage.loadContent("pages/page2", (err) => { 5793 if (err.code) { 5794 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5795 return; 5796 } 5797 console.info('Succeeded in loading the content.'); 5798 }); 5799 // 获取应用主窗口。 5800 let mainWindow: window.Window | undefined = undefined; 5801 5802 windowStage.getMainWindow((err, data) => { 5803 if (err.code) { 5804 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5805 return; 5806 } 5807 mainWindow = data; 5808 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5809 5810 let enabled = false; 5811 // 调用setResizeByDragEnabled接口。 5812 mainWindow.setResizeByDragEnabled(enabled, (err) => { 5813 if (err.code) { 5814 console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err)); 5815 return; 5816 } 5817 console.info('Succeeded in setting the function of disabling the resize by dragg window.'); 5818 }); 5819 }) 5820 } 5821}; 5822``` 5823 5824### setResizeByDragEnabled<sup>10+</sup> 5825 5826setResizeByDragEnabled(enable: boolean): Promise<void> 5827 5828禁止/使能通过拖拽方式缩放主窗口的功能。使用Promise异步回调。 5829 5830**系统接口:** 此接口为系统接口。 5831 5832**系统能力:** SystemCapability.Window.SessionManager 5833 5834**参数:** 5835 5836| 参数名 | 类型 | 必填 | 说明 | 5837| -------- | ------------------------- | ---- | ---------- | 5838| enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 | 5839 5840**返回值:** 5841 5842| 类型 | 说明 | 5843| ------------------- | ------------------------- | 5844| Promise<void> | 无返回结果的Promise对象。 | 5845 5846**错误码:** 5847 5848以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 5849 5850| 错误码ID | 错误信息 | 5851| ------- | ------------------------------ | 5852| 1300002 | This window state is abnormal. | 5853| 1300003 | This window manager service works abnormally. | 5854 5855**示例:** 5856 5857```ts 5858import UIAbility from '@ohos.app.ability.UIAbility'; 5859 5860export default class EntryAbility extends UIAbility { 5861 onWindowStageCreate(windowStage) { 5862 // 为主窗口加载对应的目标页面。 5863 windowStage.loadContent("pages/page2", (err) => { 5864 if (err.code) { 5865 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 5866 return; 5867 } 5868 console.info('Succeeded in loading the content.'); 5869 }); 5870 // 获取应用主窗口。 5871 let mainWindow: window.Window | undefined = undefined; 5872 5873 windowStage.getMainWindow((err, data) => { 5874 if (err.code) { 5875 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 5876 return; 5877 } 5878 mainWindow = data; 5879 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 5880 5881 let enabled = false; 5882 // 获取setResizeByDragEnabled接口的promise对象 5883 let promise = mainWindow.setResizeByDragEnabled(enabled); 5884 promise.then(()=> { 5885 console.info('Succeeded in setting the function of disabling the resize by dragg window.'); 5886 }).catch((err)=>{ 5887 console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err)); 5888 }); 5889 }) 5890 } 5891}; 5892``` 5893 5894### show<sup>(deprecated)</sup> 5895 5896show(callback: AsyncCallback<void>): void 5897 5898显示当前窗口,使用callback异步回调。 5899 5900> **说明:** 5901> 5902> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9)。 5903 5904**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5905 5906**参数:** 5907 5908| 参数名 | 类型 | 必填 | 说明 | 5909| -------- | ------------------------- | ---- | ---------- | 5910| callback | AsyncCallback<void> | 是 | 回调函数。 | 5911 5912**示例:** 5913 5914```ts 5915import { BusinessError } from '@ohos.base'; 5916 5917windowClass.show((err: BusinessError) => { 5918 const errCode: number = err.code; 5919 if (errCode) { 5920 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 5921 return; 5922 } 5923 console.info('Succeeded in showing the window.'); 5924}); 5925``` 5926 5927### show<sup>(deprecated)</sup> 5928 5929show(): Promise<void> 5930 5931显示当前窗口,使用Promise异步回调。 5932 5933> **说明:** 5934> 5935> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[showWindow()](#showwindow9-1)。 5936 5937**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5938 5939**返回值:** 5940 5941| 类型 | 说明 | 5942| ------------------- | ------------------------- | 5943| Promise<void> | 无返回结果的Promise对象。 | 5944 5945**示例:** 5946 5947```ts 5948import { BusinessError } from '@ohos.base'; 5949 5950let promise = windowClass.show(); 5951promise.then(() => { 5952 console.info('Succeeded in showing the window.'); 5953}).catch((err: BusinessError) => { 5954 console.error('Failed to show the window. Cause: ' + JSON.stringify(err)); 5955}); 5956``` 5957 5958### destroy<sup>(deprecated)</sup> 5959 5960destroy(callback: AsyncCallback<void>): void 5961 5962销毁当前窗口,使用callback异步回调。 5963 5964> **说明:** 5965> 5966> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9)。 5967 5968**系统能力:** SystemCapability.WindowManager.WindowManager.Core 5969 5970**参数:** 5971 5972| 参数名 | 类型 | 必填 | 说明 | 5973| -------- | ------------------------- | ---- | ---------- | 5974| callback | AsyncCallback<void> | 是 | 回调函数。 | 5975 5976**示例:** 5977 5978```ts 5979import { BusinessError } from '@ohos.base'; 5980 5981windowClass.destroy((err: BusinessError) => { 5982 const errCode: number = err.code; 5983 if (err.code) { 5984 console.error('Failed to destroy the window. Cause:' + JSON.stringify(err)); 5985 return; 5986 } 5987 console.info('Succeeded in destroying the window.'); 5988}); 5989``` 5990 5991### destroy<sup>(deprecated)</sup> 5992 5993destroy(): Promise<void> 5994 5995销毁当前窗口,使用Promise异步回调。 5996 5997> **说明:** 5998> 5999> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[destroyWindow()](#destroywindow9-1)。 6000 6001**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6002 6003**返回值:** 6004 6005| 类型 | 说明 | 6006| ------------------- | ------------------------- | 6007| Promise<void> | 无返回结果的Promise对象。 | 6008 6009**示例:** 6010 6011```ts 6012import { BusinessError } from '@ohos.base'; 6013 6014let promise = windowClass.destroy(); 6015promise.then(() => { 6016 console.info('Succeeded in destroying the window.'); 6017}).catch((err: BusinessError) => { 6018 console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); 6019}); 6020``` 6021 6022### moveTo<sup>(deprecated)</sup> 6023 6024moveTo(x: number, y: number, callback: AsyncCallback<void>): void 6025 6026移动窗口位置,使用callback异步回调。 6027 6028全屏模式窗口不支持该操作。 6029 6030> **说明:** 6031> 6032> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9)。 6033 6034**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6035 6036**参数:** 6037 6038| 参数名 | 类型 | 必填 | 说明 | 6039| -------- | ------------------------- | ---- | ------------------------------------------------- | 6040| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。 | 6041| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。 | 6042| callback | AsyncCallback<void> | 是 | 回调函数。 | 6043 6044**示例:** 6045 6046```ts 6047import { BusinessError } from '@ohos.base'; 6048 6049windowClass.moveTo(300, 300, (err: BusinessError) => { 6050 const errCode: number = err.code; 6051 if (errCode) { 6052 console.error('Failed to move the window. Cause:' + JSON.stringify(err)); 6053 return; 6054 } 6055 console.info('Succeeded in moving the window.'); 6056}); 6057``` 6058 6059### moveTo<sup>(deprecated)</sup> 6060 6061moveTo(x: number, y: number): Promise<void> 6062 6063移动窗口位置,使用Promise异步回调。 6064 6065全屏模式窗口不支持该操作。 6066 6067> **说明:** 6068> 6069> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[moveWindowTo()](#movewindowto9-1)。 6070 6071**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6072 6073**参数:** 6074 6075| 参数名 | 类型 | 必填 | 说明 | 6076| ------ | ------ | ---- | ------------------------------------------------- | 6077| x | number | 是 | 窗口在x轴方向移动的值,值为正表示右移,单位为px,该参数仅支持整数输入。 | 6078| y | number | 是 | 窗口在y轴方向移动的值,值为正表示下移,单位为px,该参数仅支持整数输入。 | 6079 6080**返回值:** 6081 6082| 类型 | 说明 | 6083| ------------------- | ------------------------- | 6084| Promise<void> | 无返回结果的Promise对象。 | 6085 6086**示例:** 6087 6088```ts 6089import { BusinessError } from '@ohos.base'; 6090 6091let promise = windowClass.moveTo(300, 300); 6092promise.then(() => { 6093 console.info('Succeeded in moving the window.'); 6094}).catch((err: BusinessError) => { 6095 console.error('Failed to move the window. Cause: ' + JSON.stringify(err)); 6096}); 6097``` 6098 6099### resetSize<sup>(deprecated)</sup> 6100 6101resetSize(width: number, height: number, callback: AsyncCallback<void>): void 6102 6103改变当前窗口大小,使用callback异步回调。 6104 6105应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 6106应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。 6107 6108系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 6109 6110设置的宽度与高度受到此约束限制,规则: 6111若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 6112若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 6113 6114全屏模式窗口不支持该操作。 6115 6116> **说明:** 6117> 6118> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。 6119 6120**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6121 6122**参数:** 6123 6124| 参数名 | 类型 | 必填 | 说明 | 6125| -------- | ------------------------- | ---- | -------------------------- | 6126| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入。 | 6127| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入。 | 6128| callback | AsyncCallback<void> | 是 | 回调函数。 | 6129 6130**示例:** 6131 6132```ts 6133import { BusinessError } from '@ohos.base'; 6134 6135windowClass.resetSize(500, 1000, (err: BusinessError) => { 6136 const errCode: number = err.code; 6137 if (errCode) { 6138 console.error('Failed to change the window size. Cause:' + JSON.stringify(err)); 6139 return; 6140 } 6141 console.info('Succeeded in changing the window size.'); 6142}); 6143``` 6144 6145### resetSize<sup>(deprecated)</sup> 6146 6147resetSize(width: number, height: number): Promise<void> 6148 6149改变当前窗口大小,使用Promise异步回调。 6150 6151应用主窗口与子窗口存在大小限制,默认宽度范围:[320, 2560],默认高度范围:[240, 2560],单位为vp。 6152应用主窗口与子窗口的最小宽度与最小高度可由产品端进行配置,配置后的最小宽度与最小高度以产品段配置值为准。 6153 6154系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。 6155 6156设置的宽度与高度受到此约束限制,规则: 6157若所设置的窗口宽/高尺寸小于窗口最小宽/高限值,则窗口最小宽/高限值生效; 6158若所设置的窗口宽/高尺寸大于窗口最大宽/高限值,则窗口最大宽/高限值生效。 6159 6160全屏模式窗口不支持该操作。 6161 6162> **说明:** 6163> 6164> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。 6165 6166**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6167 6168**参数:** 6169 6170| 参数名 | 类型 | 必填 | 说明 | 6171| ------ | ------ | ---- | -------------------------- | 6172| width | number | 是 | 目标窗口的宽度,单位为px,该参数仅支持整数输入。 | 6173| height | number | 是 | 目标窗口的高度,单位为px,该参数仅支持整数输入。 | 6174 6175**返回值:** 6176 6177| 类型 | 说明 | 6178| ------------------- | ------------------------- | 6179| Promise<void> | 无返回结果的Promise对象。 | 6180 6181**示例:** 6182 6183```ts 6184import { BusinessError } from '@ohos.base'; 6185 6186let promise = windowClass.resetSize(500, 1000); 6187promise.then(() => { 6188 console.info('Succeeded in changing the window size.'); 6189}).catch((err: BusinessError) => { 6190 console.error('Failed to change the window size. Cause: ' + JSON.stringify(err)); 6191}); 6192``` 6193 6194### setWindowType<sup>(deprecated)</sup> 6195 6196setWindowType(type: WindowType, callback: AsyncCallback<void>): void 6197 6198设置窗口类型,使用callback异步回调。 6199 6200**系统接口:** 此接口为系统接口。 6201 6202> **说明:** 6203> 6204> 从 API version 7开始支持,从API version 9开始废弃。 6205 6206**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6207 6208**参数:** 6209 6210| 参数名 | 类型 | 必填 | 说明 | 6211| -------- | ------------------------- | ---- | ---------- | 6212| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 6213| callback | AsyncCallback<void> | 是 | 回调函数。 | 6214 6215**示例:** 6216 6217```ts 6218import { BusinessError } from '@ohos.base'; 6219 6220let type = window.WindowType.TYPE_SYSTEM_ALERT; 6221windowClass.setWindowType(type, (err: BusinessError) => { 6222 const errCode: number = err.code; 6223 if (errCode) { 6224 console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); 6225 return; 6226 } 6227 console.info('Succeeded in setting the window type.'); 6228}); 6229``` 6230 6231### setWindowType<sup>(deprecated)</sup> 6232 6233setWindowType(type: WindowType): Promise<void> 6234 6235设置窗口类型,使用Promise异步回调。 6236 6237**系统接口:** 此接口为系统接口。 6238 6239> **说明:** 6240> 6241> 从 API version 7开始支持,从API version 9开始废弃。 6242 6243**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6244 6245**参数:** 6246 6247| 参数名 | 类型 | 必填 | 说明 | 6248| ------ | ------------------------- | ---- | ---------- | 6249| type | [WindowType](#windowtype7) | 是 | 窗口类型。 | 6250 6251**返回值:** 6252 6253| 类型 | 说明 | 6254| ------------------- | ------------------------- | 6255| Promise<void> | 无返回结果的Promise对象。 | 6256 6257**示例:** 6258 6259```ts 6260import { BusinessError } from '@ohos.base'; 6261 6262let type = window.WindowType.TYPE_SYSTEM_ALERT; 6263let promise = windowClass.setWindowType(type); 6264promise.then(() => { 6265 console.info('Succeeded in setting the window type.'); 6266}).catch((err: BusinessError) => { 6267 console.error('Failed to set the window type. Cause: ' + JSON.stringify(err)); 6268}); 6269``` 6270 6271### getProperties<sup>(deprecated)</sup> 6272 6273getProperties(callback: AsyncCallback<WindowProperties>): void 6274 6275获取当前窗口的属性,使用callback异步回调,返回WindowProperties。 6276 6277> **说明:** 6278> 6279> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 6280 6281**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6282 6283**参数:** 6284 6285| 参数名 | 类型 | 必填 | 说明 | 6286| -------- | ---------------------------------------------------------- | ---- | ---------------------------- | 6287| callback | AsyncCallback<[WindowProperties](#windowproperties)> | 是 | 回调函数。返回当前窗口属性。 | 6288 6289**示例:** 6290 6291```ts 6292import { BusinessError } from '@ohos.base'; 6293 6294windowClass.getProperties((err: BusinessError, data) => { 6295 const errCode: number = err.code; 6296 if (errCode) { 6297 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 6298 return; 6299 } 6300 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 6301}); 6302``` 6303 6304### getProperties<sup>(deprecated)</sup> 6305 6306getProperties(): Promise<WindowProperties> 6307 6308获取当前窗口的属性,使用Promise异步回调,返回WindowProperties。 6309 6310> **说明:** 6311> 6312> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[getWindowProperties()](#getwindowproperties9)。 6313 6314**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6315 6316**返回值:** 6317 6318| 类型 | 说明 | 6319| ---------------------------------------------------- | ------------------------------- | 6320| Promise<[WindowProperties](#windowproperties)> | Promise对象。返回当前窗口属性。 | 6321 6322**示例:** 6323 6324```ts 6325import { BusinessError } from '@ohos.base'; 6326 6327let promise = windowClass.getProperties(); 6328promise.then((data) => { 6329 console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data)); 6330}).catch((err: BusinessError) => { 6331 console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err)); 6332}); 6333``` 6334 6335### getAvoidArea<sup>(deprecated)</sup> 6336 6337getAvoidArea(type: [AvoidAreaType](#avoidareatype7), callback: AsyncCallback<[AvoidArea](#avoidarea7)>): void 6338 6339获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 6340 6341> **说明:** 6342> 6343> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 6344 6345**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6346 6347**参数:** 6348 6349| 参数名 | 类型 | 必填 | 说明 | 6350| -------- |-----------------------------------------------| ---- | ------------------------------------------------------------ | 6351| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。| 6352| callback | AsyncCallback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回窗口内容规避区域。 | 6353 6354**示例:** 6355 6356```ts 6357import { BusinessError } from '@ohos.base'; 6358 6359let type = window.AvoidAreaType.TYPE_SYSTEM; 6360windowClass.getAvoidArea(type, (err: BusinessError, data) => { 6361 const errCode: number = err.code; 6362 if (errCode) { 6363 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 6364 return; 6365 } 6366 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 6367}); 6368``` 6369 6370### getAvoidArea<sup>(deprecated)</sup> 6371 6372getAvoidArea(type: [AvoidAreaType](#avoidareatype7)): Promise<[AvoidArea](#avoidarea7)> 6373 6374获取窗口内容规避的区域;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。 6375 6376> **说明:** 6377> 6378> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[getWindowAvoidArea()](#getwindowavoidarea9)。 6379 6380**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6381 6382**参数:** 6383 6384| 参数名 | 类型 | 必填 | 说明 | 6385| ------ |----------------------------------| ---- | ------------------------------------------------------------ | 6386| type | [AvoidAreaType](#avoidareatype7) | 是 | 表示规避区类型。 | 6387 6388**返回值:** 6389 6390| 类型 | 说明 | 6391|-----------------------------------------| ----------------------------------- | 6392| Promise<[AvoidArea](#avoidarea7)> | Promise对象。返回窗口内容规避区域。 | 6393 6394**示例:** 6395 6396```ts 6397import { BusinessError } from '@ohos.base'; 6398 6399let type = window.AvoidAreaType.TYPE_SYSTEM; 6400let promise = windowClass.getAvoidArea(type); 6401promise.then((data) => { 6402 console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data)); 6403}).catch((err: BusinessError) => { 6404 console.error('Failed to obtain the area. Cause:' + JSON.stringify(err)); 6405}); 6406``` 6407 6408### setFullScreen<sup>(deprecated)</sup> 6409 6410setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void 6411 6412设置窗口的布局是否为全屏布局,使用callback异步回调。 6413全屏布局是指窗口大小为全屏幕,状态栏与导航栏不显示。 6414非全屏布局是指状态栏与导航栏显示,窗口大小避让状态栏与导航栏位置。 6415 6416> **说明:** 6417> 6418> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)实现全屏。 6419 6420**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6421 6422**参数:** 6423 6424| 参数名 | 类型 | 必填 | 说明 | 6425| ------------ | ------------------------- | ---- | ---------------------------------------------- | 6426| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 6427| callback | AsyncCallback<void> | 是 | 回调函数。 | 6428 6429**示例:** 6430 6431```ts 6432import { BusinessError } from '@ohos.base'; 6433 6434let isFullScreen: boolean = true; 6435windowClass.setFullScreen(isFullScreen, (err: BusinessError) => { 6436 const errCode: number = err.code; 6437 if (errCode) { 6438 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 6439 return; 6440 } 6441 console.info('Succeeded in enabling the full-screen mode.'); 6442}); 6443``` 6444 6445### setFullScreen<sup>(deprecated)</sup> 6446 6447setFullScreen(isFullScreen: boolean): Promise<void> 6448 6449设置窗口的布局是否为全屏布局,使用Promise异步回调。 6450全屏布局是指窗口大小为全屏幕,状态栏与导航栏不显示。 6451非全屏布局是指状态栏与导航栏显示,窗口大小避让状态栏与导航栏位置。 6452 6453> **说明:** 6454> 6455> 从 API version 6开始支持,从API version 9开始废弃,推荐联合使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)和[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)实现全屏。 6456 6457**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6458 6459**参数:** 6460 6461| 参数名 | 类型 | 必填 | 说明 | 6462| ------------ | ------- | ---- | ---------------------------------------------- | 6463| isFullScreen | boolean | 是 | 是否设为全屏布局(该全屏布局影响状态栏导航栏显示)。true表示全屏;false表示非全屏。 | 6464 6465**返回值:** 6466 6467| 类型 | 说明 | 6468| ------------------- | ------------------------- | 6469| Promise<void> | 无返回结果的Promise对象。 | 6470 6471**示例:** 6472 6473```ts 6474import { BusinessError } from '@ohos.base'; 6475 6476let isFullScreen: boolean = true; 6477let promise = windowClass.setFullScreen(isFullScreen); 6478promise.then(() => { 6479 console.info('Succeeded in enabling the full-screen mode.'); 6480}).catch((err: BusinessError) => { 6481 console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err)); 6482}); 6483``` 6484 6485### setLayoutFullScreen<sup>(deprecated)</sup> 6486 6487setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void 6488 6489设置窗口的布局是否为沉浸式布局,使用callback异步回调。 6490沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 6491非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。 6492 6493> **说明:** 6494> 6495> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9)。 6496 6497**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6498 6499**参数:** 6500 6501| 参数名 | 类型 | 必填 | 说明 | 6502| ------------------ | ------------------------- | ---- | ------------------------------------------------------------ | 6503| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 6504| callback | AsyncCallback<void> | 是 | 回调函数。 | 6505 6506**示例:** 6507 6508```ts 6509import { BusinessError } from '@ohos.base'; 6510 6511let isLayoutFullScreen: boolean = true; 6512windowClass.setLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => { 6513 const errCode: number = err.code; 6514 if (errCode) { 6515 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 6516 return; 6517 } 6518 console.info('Succeeded in setting the window layout to full-screen mode.'); 6519}); 6520``` 6521 6522### setLayoutFullScreen<sup>(deprecated)</sup> 6523 6524setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void> 6525 6526设置窗口的布局是否为沉浸式布局,使用Promise异步回调。 6527沉浸式布局是指布局不避让状态栏与导航栏,组件可能产生与其重叠的情况。 6528非沉浸式布局是指布局避让状态栏与导航栏,组件不会与其重叠。 6529 6530> **说明:** 6531> 6532> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowLayoutFullScreen()](#setwindowlayoutfullscreen9-1)。 6533 6534**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6535 6536**参数:** 6537 6538| 参数名 | 类型 | 必填 | 说明 | 6539| ------------------ | ------- | ---- | ------------------------------------------------------------ | 6540| isLayoutFullScreen | boolean | 是 | 窗口的布局是否为沉浸式布局(该沉浸式布局不影响状态栏、导航栏显示)。true表示沉浸式布局;false表示非沉浸式布局。 | 6541 6542**返回值:** 6543 6544| 类型 | 说明 | 6545| ------------------- | ------------------------- | 6546| Promise<void> | 无返回结果的Promise对象。 | 6547 6548**示例:** 6549 6550```ts 6551import { BusinessError } from '@ohos.base'; 6552 6553let isLayoutFullScreen: boolean = true; 6554let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen); 6555promise.then(() => { 6556 console.info('Succeeded in setting the window layout to full-screen mode.'); 6557}).catch((err: BusinessError) => { 6558 console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 6559}); 6560``` 6561 6562### setSystemBarEnable<sup>(deprecated)</sup> 6563 6564setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallback<void>): void 6565 6566设置窗口全屏模式时导航栏、状态栏的可见模式,使用callback异步回调。 6567 6568> **说明:** 6569> 6570> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9)。 6571 6572**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6573 6574**参数:** 6575 6576| 参数名 | 类型 | 必填 | 说明 | 6577| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 6578| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 6579| callback | AsyncCallback<void> | 是 | 回调函数。 | 6580 6581**示例:** 6582 6583```ts 6584// 此处以不显示导航栏、状态栏为例 6585import { BusinessError } from '@ohos.base'; 6586 6587let names: Array<'status' | 'navigation'> = []; 6588windowClass.setSystemBarEnable(names, (err: BusinessError) => { 6589 const errCode: number = err.code; 6590 if (errCode) { 6591 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 6592 return; 6593 } 6594 console.info('Succeeded in setting the system bar to be invisible.'); 6595}); 6596``` 6597 6598### setSystemBarEnable<sup>(deprecated)</sup> 6599 6600setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void> 6601 6602设置窗口全屏模式时导航栏、状态栏的可见模式,使用Promise异步回调。 6603 6604> **说明:** 6605> 6606> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarEnable()](#setwindowsystembarenable9-1)。 6607 6608**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6609 6610**参数:** 6611 6612| 参数名 | 类型 | 必填 | 说明 | 6613| ------ | ---------------------------- | ---- | ------------------------ | 6614| names | Array<'status'\|'navigation'> | 是 | 设置窗口全屏模式时状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。 | 6615 6616**返回值:** 6617 6618| 类型 | 说明 | 6619| ------------------- | ------------------------- | 6620| Promise<void> | 无返回结果的Promise对象。 | 6621 6622**示例:** 6623 6624```ts 6625// 此处以不显示导航栏、状态栏为例 6626import { BusinessError } from '@ohos.base'; 6627 6628let names: Array<'status' | 'navigation'> = []; 6629let promise = windowClass.setSystemBarEnable(names); 6630promise.then(() => { 6631 console.info('Succeeded in setting the system bar to be invisible.'); 6632}).catch((err: BusinessError) => { 6633 console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err)); 6634}); 6635``` 6636 6637### setSystemBarProperties<sup>(deprecated)</sup> 6638 6639setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void 6640 6641设置窗口全屏模式时窗口内导航栏、状态栏的属性,使用callback异步回调。 6642 6643> **说明:** 6644> 6645> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9)。 6646 6647**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6648 6649**参数:** 6650 6651| 参数名 | 类型 | 必填 | 说明 | 6652| ------------------- | ------------------------------------------- | ---- | ---------------------- | 6653| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 6654| callback | AsyncCallback<void> | 是 | 回调函数。 | 6655 6656**示例:** 6657 6658```ts 6659import { BusinessError } from '@ohos.base'; 6660 6661let SystemBarProperties: window.SystemBarProperties = { 6662 statusBarColor: '#ff00ff', 6663 navigationBarColor: '#00ff00', 6664 //以下两个属性从API Version8开始支持 6665 statusBarContentColor: '#ffffff', 6666 navigationBarContentColor: '#00ffff' 6667}; 6668windowClass.setSystemBarProperties(SystemBarProperties, (err) => { 6669 const errCode: number = err.code; 6670 if (errCode) { 6671 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 6672 return; 6673 } 6674 console.info('Succeeded in setting the system bar properties.'); 6675}); 6676``` 6677 6678### setSystemBarProperties<sup>(deprecated)</sup> 6679 6680setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void> 6681 6682设置窗口全屏模式时窗口内导航栏、状态栏的属性,使用Promise异步回调。 6683 6684> **说明:** 6685> 6686> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowSystemBarProperties()](#setwindowsystembarproperties9-1)。 6687 6688**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6689 6690**参数:** 6691 6692| 参数名 | 类型 | 必填 | 说明 | 6693| ------------------- | ------------------------------------------- | ---- | ---------------------- | 6694| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏、状态栏的属性。 | 6695 6696**返回值:** 6697 6698| 类型 | 说明 | 6699| ------------------- | ------------------------- | 6700| Promise<void> | 无返回结果的Promise对象。 | 6701 6702**示例:** 6703 6704```ts 6705import { BusinessError } from '@ohos.base'; 6706 6707let SystemBarProperties: window.SystemBarProperties = { 6708 statusBarColor: '#ff00ff', 6709 navigationBarColor: '#00ff00', 6710 //以下两个属性从API Version8开始支持 6711 statusBarContentColor: '#ffffff', 6712 navigationBarContentColor: '#00ffff' 6713}; 6714let promise = windowClass.setSystemBarProperties(SystemBarProperties); 6715promise.then(() => { 6716 console.info('Succeeded in setting the system bar properties.'); 6717}).catch((err: BusinessError) => { 6718 console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); 6719}); 6720``` 6721 6722### loadContent<sup>(deprecated)</sup> 6723 6724loadContent(path: string, callback: AsyncCallback<void>): void 6725 6726为当前窗口加载具体页面内容,使用callback异步回调。 6727 6728> **说明:** 6729> 6730> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9)。 6731 6732**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6733 6734**参数:** 6735 6736| 参数名 | 类型 | 必填 | 说明 | 6737| -------- | ------------------------- | ---- | -------------------- | 6738| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。 | 6739| callback | AsyncCallback<void> | 是 | 回调函数。 | 6740 6741**示例:** 6742 6743```ts 6744import { BusinessError } from '@ohos.base'; 6745 6746windowClass.loadContent('pages/page2/page3', (err: BusinessError) => { 6747 const errCode: number = err.code; 6748 if (errCode) { 6749 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 6750 return; 6751 } 6752 console.info('Succeeded in loading the content.'); 6753}); 6754``` 6755 6756### loadContent<sup>(deprecated)</sup> 6757 6758loadContent(path: string): Promise<void> 6759 6760为当前窗口加载具体页面内容,使用Promise异步回调。 6761 6762> **说明:** 6763> 6764> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setUIContent()](#setuicontent9-1)。 6765 6766**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6767 6768**参数:** 6769 6770| 参数名 | 类型 | 必填 | 说明 | 6771| ------ | ------ | ---- | -------------------- | 6772| path | string | 是 | 要加载到窗口中的页面内容的路径,Stage模型下该路径需添加到工程的main_pages.json文件中,FA模型下该路径需添加到工程的config.json文件中。| 6773 6774**返回值:** 6775 6776| 类型 | 说明 | 6777| ------------------- | ------------------------- | 6778| Promise<void> | 无返回结果的Promise对象。 | 6779 6780**示例:** 6781 6782```ts 6783import { BusinessError } from '@ohos.base'; 6784 6785let promise = windowClass.loadContent('pages/page2/page3'); 6786promise.then(() => { 6787 console.info('Succeeded in loading the content.'); 6788}).catch((err: BusinessError) => { 6789 console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); 6790}); 6791``` 6792 6793### isShowing<sup>(deprecated)</sup> 6794 6795isShowing(callback: AsyncCallback<boolean>): void 6796 6797判断当前窗口是否已显示,使用callback异步回调。 6798 6799> **说明:** 6800> 6801> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 6802 6803**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6804 6805**参数:** 6806 6807| 参数名 | 类型 | 必填 | 说明 | 6808| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 6809| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 6810 6811**示例:** 6812 6813```ts 6814import { BusinessError } from '@ohos.base'; 6815 6816windowClass.isShowing((err: BusinessError, data) => { 6817 const errCode: number = err.code; 6818 if (errCode) { 6819 console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err)); 6820 return; 6821 } 6822 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 6823}); 6824``` 6825 6826### isShowing<sup>(deprecated)</sup> 6827 6828isShowing(): Promise<boolean> 6829 6830判断当前窗口是否已显示,使用Promise异步回调。 6831 6832> **说明:** 6833> 6834> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[isWindowShowing()](#iswindowshowing9)。 6835 6836**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6837 6838**返回值:** 6839 6840| 类型 | 说明 | 6841| ---------------------- | ------------------------------------------------------------ | 6842| Promise<boolean> | Promise对象。返回true表示当前窗口已显示,返回false表示当前窗口未显示。 | 6843 6844**示例:** 6845 6846```ts 6847import { BusinessError } from '@ohos.base'; 6848 6849let promise = windowClass.isShowing(); 6850promise.then((data) => { 6851 console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data)); 6852}).catch((err: BusinessError) => { 6853 console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err)); 6854}); 6855``` 6856 6857### on('systemAvoidAreaChange')<sup>(deprecated)</sup> 6858 6859on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void 6860 6861开启系统规避区变化的监听。 6862 6863> **说明:** 6864> 6865> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[on('avoidAreaChange')](#onavoidareachange9)。 6866 6867**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6868 6869**参数:** 6870 6871| 参数名 | 类型 | 必填 | 说明 | 6872| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 6873| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 6874| callback | Callback<[AvoidArea](#avoidarea7)> | 是 | 回调函数。返回当前规避区。 | 6875 6876**示例:** 6877 6878```ts 6879windowClass.on('systemAvoidAreaChange', (data) => { 6880 console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data)); 6881}); 6882``` 6883 6884### off('systemAvoidAreaChange')<sup>(deprecated)</sup> 6885 6886off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void 6887 6888关闭系统规避区变化的监听。 6889 6890> **说明:** 6891> 6892> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[off('avoidAreaChange')](#offavoidareachange9)。 6893 6894**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6895 6896**参数:** 6897 6898| 参数名 | 类型 | 必填 | 说明 | 6899| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 6900| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统规避区变化事件。 | 6901| callback | Callback<[AvoidArea](#avoidarea7)> | 否 | 回调函数。返回当前规避区。若传入参数,则关闭该监听。若未传入参数,则关闭所有系统规避区变化的监听。 | 6902 6903**示例:** 6904 6905```ts 6906windowClass.off('systemAvoidAreaChange'); 6907``` 6908 6909### isSupportWideGamut<sup>(deprecated)</sup> 6910 6911isSupportWideGamut(callback: AsyncCallback<boolean>): void 6912 6913判断当前窗口是否支持广色域模式,使用callback异步回调。 6914 6915> **说明:** 6916> 6917> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9)。 6918 6919**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6920 6921**参数:** 6922 6923| 参数名 | 类型 | 必填 | 说明 | 6924| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | 6925| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 6926 6927**示例:** 6928 6929```ts 6930import { BusinessError } from '@ohos.base'; 6931 6932windowClass.isSupportWideGamut((err: BusinessError, data) => { 6933 const errCode: number = err.code; 6934 if (errCode) { 6935 console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err)); 6936 return; 6937 } 6938 console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data)); 6939}); 6940``` 6941 6942### isSupportWideGamut<sup>(deprecated)</sup> 6943 6944isSupportWideGamut(): Promise<boolean> 6945 6946判断当前窗口是否支持广色域模式,使用Promise异步回调。 6947 6948> **说明:** 6949> 6950> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[isWindowSupportWideGamut()](#iswindowsupportwidegamut9-1)。 6951 6952**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6953 6954**返回值:** 6955 6956| 类型 | 说明 | 6957| ---------------------- | ------------------------------------------------------------ | 6958| Promise<boolean> | Promise对象。返回true表示当前窗口支持广色域模式,返回false表示当前窗口不支持广色域模式。 | 6959 6960**示例:** 6961 6962```ts 6963import { BusinessError } from '@ohos.base'; 6964 6965let promise = windowClass.isSupportWideGamut(); 6966promise.then((data) => { 6967 console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data)); 6968}).catch((err: BusinessError) => { 6969 console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err)); 6970}); 6971``` 6972 6973### setColorSpace<sup>(deprecated)</sup> 6974 6975setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void 6976 6977设置当前窗口为广色域模式或默认色域模式,使用callback异步回调。 6978 6979> **说明:** 6980> 6981> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9)。 6982 6983**系统能力:** SystemCapability.WindowManager.WindowManager.Core 6984 6985**参数:** 6986 6987| 参数名 | 类型 | 必填 | 说明 | 6988| ---------- | ------------------------- | ---- | ------------ | 6989| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 6990| callback | AsyncCallback<void> | 是 | 回调函数。 | 6991 6992**示例:** 6993 6994```ts 6995import { BusinessError } from '@ohos.base'; 6996 6997windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err: BusinessError) => { 6998 const errCode: number = err.code; 6999 if (errCode) { 7000 console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err)); 7001 return; 7002 } 7003 console.info('Succeeded in setting window colorspace.'); 7004}); 7005``` 7006 7007### setColorSpace<sup>(deprecated)</sup> 7008 7009setColorSpace(colorSpace:ColorSpace): Promise<void> 7010 7011设置当前窗口为广色域模式或默认色域模式,使用Promise异步回调。 7012 7013> **说明:** 7014> 7015> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[setWindowColorSpace()](#setwindowcolorspace9-1)。 7016 7017**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7018 7019**参数:** 7020 7021| 参数名 | 类型 | 必填 | 说明 | 7022| ---------- | ------------------------- | ---- | -------------- | 7023| colorSpace | [ColorSpace](#colorspace8) | 是 | 设置色域模式。 | 7024 7025**返回值:** 7026 7027| 类型 | 说明 | 7028| ------------------- | ------------------------- | 7029| Promise<void> | 无返回结果的Promise对象。 | 7030 7031**示例:** 7032 7033```ts 7034import { BusinessError } from '@ohos.base'; 7035 7036let promise = windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT); 7037promise.then(() => { 7038 console.info('Succeeded in setting window colorspace.'); 7039}).catch((err: BusinessError) => { 7040 console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err)); 7041}); 7042``` 7043 7044### getColorSpace<sup>(deprecated)</sup> 7045 7046getColorSpace(callback: AsyncCallback<ColorSpace>): void 7047 7048获取当前窗口色域模式,使用callback异步回调。 7049 7050> **说明:** 7051> 7052> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 7053 7054**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7055 7056**参数:** 7057 7058| 参数名 | 类型 | 必填 | 说明 | 7059| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- | 7060| callback | AsyncCallback<[ColorSpace](#colorspace8)> | 是 | 回调函数。当获取成功,err为undefined,data为当前色域模式。 | 7061 7062**示例:** 7063 7064```ts 7065import { BusinessError } from '@ohos.base'; 7066 7067windowClass.getColorSpace((err: BusinessError, data) => { 7068 const errCode: number = err.code; 7069 if (errCode) { 7070 console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err)); 7071 return; 7072 } 7073 console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data)); 7074}); 7075``` 7076 7077### getColorSpace<sup>(deprecated)</sup> 7078 7079getColorSpace(): Promise<ColorSpace> 7080 7081获取当前窗口色域模式,使用Promise异步回调。 7082 7083> **说明:** 7084> 7085> 从 API version 8开始支持,从API version 9开始废弃,推荐使用[getWindowColorSpace()](#getwindowcolorspace9)。 7086 7087**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7088 7089**返回值:** 7090 7091| 类型 | 说明 | 7092| ---------------------------------------- | ------------------------------- | 7093| Promise<[ColorSpace](#colorspace8)> | Promise对象。返回当前色域模式。 | 7094 7095**示例:** 7096 7097```ts 7098import { BusinessError } from '@ohos.base'; 7099 7100let promise = windowClass.getColorSpace(); 7101promise.then((data) => { 7102 console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data)); 7103}).catch((err: BusinessError) => { 7104 console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err)); 7105}); 7106``` 7107 7108### setBackgroundColor<sup>(deprecated)</sup> 7109 7110setBackgroundColor(color: string, callback: AsyncCallback<void>): void 7111 7112设置窗口的背景色,使用callback异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7113 7114> **说明:** 7115> 7116> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 7117 7118**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7119 7120**参数:** 7121 7122| 参数名 | 类型 | 必填 | 说明 | 7123| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 7124| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 7125| callback | AsyncCallback<void> | 是 | 回调函数。 | 7126 7127**示例:** 7128 7129```ts 7130import { BusinessError } from '@ohos.base'; 7131 7132let color: string = '#00ff33'; 7133windowClass.setBackgroundColor(color, (err: BusinessError) => { 7134 const errCode: number = err.code; 7135 if (errCode) { 7136 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 7137 return; 7138 } 7139 console.info('Succeeded in setting the background color.'); 7140}); 7141``` 7142 7143### setBackgroundColor<sup>(deprecated)</sup> 7144 7145setBackgroundColor(color: string): Promise<void> 7146 7147设置窗口的背景色,使用Promise异步回调。Stage模型下,该接口需要在[loadContent()](#loadcontent9)或[setUIContent()](#setuicontent9)调用生效后使用。 7148 7149> **说明:** 7150> 7151> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBackgroundColor()](#setwindowbackgroundcolor9)。 7152 7153**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7154 7155**参数:** 7156 7157| 参数名 | 类型 | 必填 | 说明 | 7158| ------ | ------ | ---- | ------------------------------------------------------------ | 7159| color | string | 是 | 需要设置的背景色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | 7160 7161**返回值:** 7162 7163| 类型 | 说明 | 7164| ------------------- | ------------------------- | 7165| Promise<void> | 无返回结果的Promise对象。 | 7166 7167**示例:** 7168 7169```ts 7170import { BusinessError } from '@ohos.base'; 7171 7172let color: string = '#00ff33'; 7173let promise = windowClass.setBackgroundColor(color); 7174promise.then(() => { 7175 console.info('Succeeded in setting the background color.'); 7176}).catch((err: BusinessError) => { 7177 console.error('Failed to set the background color. Cause: ' + JSON.stringify(err)); 7178}); 7179``` 7180 7181### setBrightness<sup>(deprecated)</sup> 7182 7183setBrightness(brightness: number, callback: AsyncCallback<void>): void 7184 7185允许应用窗口设置屏幕亮度值,使用callback异步回调。 7186 7187当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 7188 7189> **说明:** 7190> 7191> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9)。 7192 7193**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7194 7195**参数:** 7196 7197| 参数名 | 类型 | 必填 | 说明 | 7198| ---------- | ------------------------- | ---- |---------------------------------------| 7199| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 7200| callback | AsyncCallback<void> | 是 | 回调函数。 | 7201 7202**示例:** 7203 7204```ts 7205import { BusinessError } from '@ohos.base'; 7206 7207let brightness: number = 1; 7208windowClass.setBrightness(brightness, (err: BusinessError) => { 7209 const errCode: number = err.code; 7210 if (errCode) { 7211 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 7212 return; 7213 } 7214 console.info('Succeeded in setting the brightness.'); 7215}); 7216``` 7217 7218### setBrightness<sup>(deprecated)</sup> 7219 7220setBrightness(brightness: number): Promise<void> 7221 7222允许应用窗口设置屏幕亮度值,使用Promise异步回调。 7223 7224当前屏幕亮度规格:窗口设置屏幕亮度生效时,控制中心不可以调整系统屏幕亮度,窗口恢复默认系统亮度之后,控制中心可以调整系统屏幕亮度。 7225 7226> **说明:** 7227> 7228> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowBrightness()](#setwindowbrightness9-1)。 7229 7230**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7231 7232**参数:** 7233 7234| 参数名 | 类型 | 必填 | 说明 | 7235| ---------- | ------ | ---- |------------------------------------------| 7236| brightness | number | 是 | 屏幕亮度值。该参数为浮点数,取值范围为[0.0, 1.0]或-1.0。1.0表示最亮,-1.0表示默认亮度。 | 7237 7238**返回值:** 7239 7240| 类型 | 说明 | 7241| ------------------- | ------------------------- | 7242| Promise<void> | 无返回结果的Promise对象。 | 7243 7244**示例:** 7245 7246```ts 7247import { BusinessError } from '@ohos.base'; 7248 7249let brightness: number = 1; 7250let promise = windowClass.setBrightness(brightness); 7251promise.then(() => { 7252 console.info('Succeeded in setting the brightness.'); 7253}).catch((err: BusinessError) => { 7254 console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err)); 7255}); 7256``` 7257 7258### setDimBehind<sup>(deprecated)</sup> 7259 7260setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void 7261 7262窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调。 7263 7264> **说明:** 7265> 7266> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 7267 7268**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7269 7270**参数:** 7271 7272| 参数名 | 类型 | 必填 | 说明 | 7273| -------------- | ------------------------- | ---- |----------------------------------------| 7274| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为[0.0, 1.0],取1.0时表示最暗。 | 7275| callback | AsyncCallback<void> | 是 | 回调函数。 | 7276 7277**示例:** 7278 7279```ts 7280import { BusinessError } from '@ohos.base'; 7281 7282windowClass.setDimBehind(0.5, (err: BusinessError) => { 7283 const errCode: number = err.code; 7284 if (errCode) { 7285 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 7286 return; 7287 } 7288 console.info('Succeeded in setting the dimness.'); 7289}); 7290``` 7291 7292### setDimBehind<sup>(deprecated)</sup> 7293 7294setDimBehind(dimBehindValue: number): Promise<void> 7295 7296窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调。 7297 7298> **说明:** 7299> 7300> 该接口不支持使用。从 API version 7开始支持,从API version 9开始废弃。 7301 7302**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7303 7304**参数:** 7305 7306| 参数名 | 类型 | 必填 | 说明 | 7307| -------------- | ------ | ---- | -------------------------------------------------- | 7308| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 | 7309 7310**返回值:** 7311 7312| 类型 | 说明 | 7313| ------------------- | ------------------------- | 7314| Promise<void> | 无返回结果的Promise对象。 | 7315 7316**示例:** 7317 7318```ts 7319import { BusinessError } from '@ohos.base'; 7320 7321let promise = windowClass.setDimBehind(0.5); 7322promise.then(() => { 7323 console.info('Succeeded in setting the dimness.'); 7324}).catch((err: BusinessError) => { 7325 console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err)); 7326}); 7327``` 7328 7329### setFocusable<sup>(deprecated)</sup> 7330 7331setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void 7332 7333设置点击时是否支持切换焦点窗口,使用callback异步回调。 7334 7335> **说明:** 7336> 7337> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9)。 7338 7339**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7340 7341**参数:** 7342 7343| 参数名 | 类型 | 必填 | 说明 | 7344| ----------- | ------------------------- | ---- | ---------------------------- | 7345| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 7346| callback | AsyncCallback<void> | 是 | 回调函数。 | 7347 7348**示例:** 7349 7350```ts 7351import { BusinessError } from '@ohos.base'; 7352 7353let isFocusable: boolean = true; 7354windowClass.setFocusable(isFocusable, (err: BusinessError) => { 7355 const errCode: number = err.code; 7356 if (errCode) { 7357 console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err)); 7358 return; 7359 } 7360 console.info('Succeeded in setting the window to be focusable.'); 7361}); 7362``` 7363 7364### setFocusable<sup>(deprecated)</sup> 7365 7366setFocusable(isFocusable: boolean): Promise<void> 7367 7368设置点击时是否支持切换焦点窗口,使用Promise异步回调。 7369 7370> **说明:** 7371> 7372> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowFocusable()](#setwindowfocusable9-1)。 7373 7374**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7375 7376**参数:** 7377 7378| 参数名 | 类型 | 必填 | 说明 | 7379| ----------- | ------- | ---- | ---------------------------- | 7380| isFocusable | boolean | 是 | 点击时是否支持切换焦点窗口。true表示支持;false表示不支持。 | 7381 7382**返回值:** 7383 7384| 类型 | 说明 | 7385| ------------------- | ------------------------- | 7386| Promise<void> | 无返回结果的Promise对象。 | 7387 7388**示例:** 7389 7390```ts 7391import { BusinessError } from '@ohos.base'; 7392 7393let isFocusable: boolean = true; 7394let promise = windowClass.setFocusable(isFocusable); 7395promise.then(() => { 7396 console.info('Succeeded in setting the window to be focusable.'); 7397}).catch((err: BusinessError) => { 7398 console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err)); 7399}); 7400``` 7401 7402### setKeepScreenOn<sup>(deprecated)</sup> 7403 7404setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void 7405 7406设置屏幕是否为常亮状态,使用callback异步回调。 7407 7408> **说明:** 7409> 7410> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9)。 7411 7412**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7413 7414**参数:** 7415 7416| 参数名 | 类型 | 必填 | 说明 | 7417| -------------- | ------------------------- | ---- | ------------------------ | 7418| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 7419| callback | AsyncCallback<void> | 是 | 回调函数。 | 7420 7421**示例:** 7422 7423```ts 7424import { BusinessError } from '@ohos.base'; 7425 7426let isKeepScreenOn: boolean = true; 7427windowClass.setKeepScreenOn(isKeepScreenOn, (err: BusinessError) => { 7428 const errCode: number = err.code; 7429 if (errCode) { 7430 console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 7431 return; 7432 } 7433 console.info('Succeeded in setting the screen to be always on.'); 7434}); 7435``` 7436 7437### setKeepScreenOn<sup>(deprecated)</sup> 7438 7439setKeepScreenOn(isKeepScreenOn: boolean): Promise<void> 7440 7441设置屏幕是否为常亮状态,使用Promise异步回调。 7442 7443> **说明:** 7444> 7445> 从 API version 6开始支持,从API version 9开始废弃,推荐使用[setWindowKeepScreenOn()](#setwindowkeepscreenon9-1)。 7446 7447**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7448 7449**参数:** 7450 7451| 参数名 | 类型 | 必填 | 说明 | 7452| -------------- | ------- | ---- | ------------------------ | 7453| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。true表示常亮;false表示不常亮。 | 7454 7455**返回值:** 7456 7457| 类型 | 说明 | 7458| ------------------- | ------------------------- | 7459| Promise<void> | 无返回结果的Promise对象。 | 7460 7461**示例:** 7462 7463```ts 7464import { BusinessError } from '@ohos.base'; 7465 7466let isKeepScreenOn: boolean = true; 7467let promise = windowClass.setKeepScreenOn(isKeepScreenOn); 7468promise.then(() => { 7469 console.info('Succeeded in setting the screen to be always on.'); 7470}).catch((err: BusinessError) => { 7471 console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); 7472}); 7473``` 7474 7475### setOutsideTouchable<sup>(deprecated)</sup> 7476 7477setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void 7478 7479设置是否允许可点击子窗口之外的区域,使用callback异步回调。 7480 7481> **说明:** 7482> 7483> 从 API version 7开始支持,从API version 9开始废弃。 7484> 7485> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 7486 7487**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7488 7489**参数:** 7490 7491| 参数名 | 类型 | 必填 | 说明 | 7492| --------- | ------------------------- | ---- | ---------------- | 7493| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 7494| callback | AsyncCallback<void> | 是 | 回调函数。 | 7495 7496**示例:** 7497 7498```ts 7499import { BusinessError } from '@ohos.base'; 7500 7501if (!windowClass) { 7502 console.info('Failed to load the content. Cause: windowClass is null'); 7503} 7504else { 7505 (windowClass as window.Window).setOutsideTouchable(true, (err: BusinessError) => { 7506 const errCode: number = err.code; 7507 if (errCode) { 7508 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 7509 return; 7510 } 7511 console.info('Succeeded in setting the area to be touchable.'); 7512 }); 7513} 7514``` 7515 7516### setOutsideTouchable<sup>(deprecated)</sup> 7517 7518setOutsideTouchable(touchable: boolean): Promise<void> 7519 7520设置是否允许可点击子窗口之外的区域,使用Promise异步回调。。 7521 7522> **说明:** 7523> 7524> 从 API version 7开始支持,从API version 9开始废弃。 7525> 7526> 从 API version 9开始,系统默认允许点击子窗口之外的区域,此接口不再支持使用,也不再提供替代接口。 7527 7528**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7529 7530**参数:** 7531 7532| 参数名 | 类型 | 必填 | 说明 | 7533| --------- | ------- | ---- | ---------------- | 7534| touchable | boolean | 是 | 设置是否可点击。true表示可点击;false表示不可点击。 | 7535 7536**返回值:** 7537 7538| 类型 | 说明 | 7539| ------------------- | ------------------------- | 7540| Promise<void> | 无返回结果的Promise对象。 | 7541 7542**示例:** 7543 7544```ts 7545import { BusinessError } from '@ohos.base'; 7546 7547if (!windowClass) { 7548 console.info('Failed to load the content. Cause: windowClass is null'); 7549} 7550else { 7551let promise = (windowClass as window.Window).setOutsideTouchable(true); 7552promise.then(() => { 7553 console.info('Succeeded in setting the area to be touchable.'); 7554}).catch((err: BusinessError) => { 7555 console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err)); 7556}); 7557} 7558``` 7559 7560### setPrivacyMode<sup>(deprecated)</sup> 7561 7562setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void 7563 7564设置窗口是否为隐私模式,使用callback异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 7565 7566> **说明:** 7567> 7568> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9)。 7569 7570**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7571 7572**参数:** 7573 7574| 参数名 | 类型 | 必填 | 说明 | 7575| ------------- | ------------------------- | ---- | -------------------- | 7576| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 7577| callback | AsyncCallback<void> | 是 | 回调函数。 | 7578 7579**示例:** 7580 7581```ts 7582import { BusinessError } from '@ohos.base'; 7583 7584let isPrivacyMode: boolean = true; 7585windowClass.setPrivacyMode(isPrivacyMode, (err: BusinessError) => { 7586 const errCode: number = err.code; 7587 if (errCode) { 7588 console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err)); 7589 return; 7590 } 7591 console.info('Succeeded in setting the window to privacy mode.'); 7592}); 7593``` 7594 7595### setPrivacyMode<sup>(deprecated)</sup> 7596 7597setPrivacyMode(isPrivacyMode: boolean): Promise<void> 7598 7599设置窗口是否为隐私模式,使用Promise异步回调。设置为隐私模式的窗口,窗口内容将无法被截屏或录屏。此接口可用于禁止截屏/录屏的场景。 7600 7601> **说明:** 7602> 7603> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowPrivacyMode()](#setwindowprivacymode9-1)。 7604 7605**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7606 7607**参数:** 7608 7609| 参数名 | 类型 | 必填 | 说明 | 7610| ------------- | ------- | ---- | -------------------- | 7611| isPrivacyMode | boolean | 是 | 窗口是否为隐私模式。true表示模式开启;false表示模式关闭。 | 7612 7613**返回值:** 7614 7615| 类型 | 说明 | 7616| ------------------- | ------------------------- | 7617| Promise<void> | 无返回结果的Promise对象。 | 7618 7619**示例:** 7620 7621```ts 7622import { BusinessError } from '@ohos.base'; 7623 7624let isPrivacyMode: boolean = true; 7625let promise = windowClass.setPrivacyMode(isPrivacyMode); 7626promise.then(() => { 7627 console.info('Succeeded in setting the window to privacy mode.'); 7628}).catch((err: BusinessError) => { 7629 console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err)); 7630}); 7631``` 7632 7633### setTouchable<sup>(deprecated)</sup> 7634 7635setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void 7636 7637设置窗口是否为可触状态,使用callback异步回调。 7638 7639> **说明:** 7640> 7641> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9)。 7642 7643**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7644 7645**参数:** 7646 7647| 参数名 | 类型 | 必填 | 说明 | 7648| ----------- | ------------------------- | ---- | -------------------- | 7649| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 7650| callback | AsyncCallback<void> | 是 | 回调函数。 | 7651 7652**示例:** 7653 7654```ts 7655import { BusinessError } from '@ohos.base'; 7656 7657let isTouchable = true; 7658if (!windowClass) { 7659 console.info('Failed to load the content. Cause: windowClass is null'); 7660} 7661else { 7662 (windowClass as window.Window).setTouchable(isTouchable, (err: BusinessError) => { 7663 const errCode: number = err.code; 7664 if (errCode) { 7665 console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err)); 7666 return; 7667 } 7668 console.info('Succeeded in setting the window to be touchable.'); 7669 }); 7670} 7671``` 7672 7673### setTouchable<sup>(deprecated)</sup> 7674 7675setTouchable(isTouchable: boolean): Promise<void> 7676 7677设置窗口是否为可触状态,使用Promise异步回调。 7678 7679> **说明:** 7680> 7681> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[setWindowTouchable()](#setwindowtouchable9-1)。 7682 7683**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7684 7685**参数:** 7686 7687| 参数名 | 类型 | 必填 | 说明 | 7688| ----------- | ------- | ---- | -------------------- | 7689| isTouchable | boolean | 是 | 窗口是否为可触状态。true表示可触;false表示不可触。 | 7690 7691**返回值:** 7692 7693| 类型 | 说明 | 7694| ------------------- | ------------------------- | 7695| Promise<void> | 无返回结果的Promise对象。 | 7696 7697**示例:** 7698 7699```ts 7700import { BusinessError } from '@ohos.base'; 7701 7702let isTouchable = true; 7703let promise = windowClass.setTouchable(isTouchable); 7704promise.then(() => { 7705 console.info('Succeeded in setting the window to be touchable.'); 7706}).catch((err: BusinessError) => { 7707 console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err)); 7708}); 7709``` 7710 7711## WindowStageEventType<sup>9+</sup> 7712 7713WindowStage生命周期。 7714 7715**模型约束:** 此接口仅可在Stage模型下使用。 7716 7717**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7718 7719| 名称 | 值 | 说明 | 7720| ---------- | ------ | ---------- | 7721| SHOWN | 1 | 切到前台。 | 7722| ACTIVE | 2 | 获焦状态。 | 7723| INACTIVE | 3 | 失焦状态。 | 7724| HIDDEN | 4 | 切到后台。 | 7725 7726## WindowStage<sup>9+</sup> 7727 7728窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 7729 7730下列API示例中都需在[onWindowStageCreate()](js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 7731 7732### getMainWindow<sup>9+</sup> 7733 7734getMainWindow(callback: AsyncCallback<Window>): void 7735 7736获取该WindowStage实例下的主窗口,使用callback异步回调。 7737 7738**模型约束:** 此接口仅可在Stage模型下使用。 7739 7740**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7741 7742**参数:** 7743 7744| 参数名 | 类型 | 必填 | 说明 | 7745| -------- | -------------------------------------- | ---- | --------------------------------------------- | 7746| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的主窗口对象。 | 7747 7748**错误码:** 7749 7750以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 7751 7752| 错误码ID | 错误信息 | 7753| ------- | ------------------------------ | 7754| 1300002 | This window state is abnormal. | 7755| 1300005 | This window stage is abnormal. | 7756 7757**示例:** 7758 7759```ts 7760import UIAbility from '@ohos.app.ability.UIAbility'; 7761import window from '@ohos.window'; 7762import { BusinessError } from '@ohos.base'; 7763 7764export default class EntryAbility extends UIAbility { 7765 // ... 7766 7767 onWindowStageCreate(windowStage: window.WindowStage) { 7768 console.log('onWindowStageCreate'); 7769 let windowClass: window.Window | undefined = undefined; 7770 windowStage.getMainWindow((err: BusinessError, data) => { 7771 const errCode: number = err.code; 7772 if (errCode) { 7773 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 7774 return; 7775 } 7776 windowClass = data; 7777 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7778 }); 7779 } 7780}; 7781``` 7782 7783### getMainWindow<sup>9+</sup> 7784 7785getMainWindow(): Promise<Window> 7786 7787获取该WindowStage实例下的主窗口,使用Promise异步回调。 7788 7789**模型约束:** 此接口仅可在Stage模型下使用。 7790 7791**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7792 7793**返回值:** 7794 7795| 类型 | 说明 | 7796| -------------------------------- | ------------------------------------------------ | 7797| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的主窗口对象。 | 7798 7799**错误码:** 7800 7801以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 7802 7803| 错误码ID | 错误信息 | 7804| ------- | ------------------------------ | 7805| 1300002 | This window state is abnormal. | 7806| 1300005 | This window stage is abnormal. | 7807 7808**示例:** 7809 7810```ts 7811import UIAbility from '@ohos.app.ability.UIAbility'; 7812import window from '@ohos.window'; 7813import { BusinessError } from '@ohos.base'; 7814 7815export default class EntryAbility extends UIAbility { 7816 // ... 7817 7818 onWindowStageCreate(windowStage: window.WindowStage) { 7819 console.log('onWindowStageCreate'); 7820 let windowClass: window.Window | undefined = undefined; 7821 let promise = windowStage.getMainWindow(); 7822 promise.then((data) => { 7823 windowClass = data; 7824 console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); 7825 }).catch((err: BusinessError) => { 7826 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); 7827 }); 7828 } 7829}; 7830``` 7831 7832### getMainWindowSync<sup>9+</sup> 7833 7834getMainWindowSync(): Window 7835 7836获取该WindowStage实例下的主窗口。 7837 7838**模型约束:** 此接口仅可在Stage模型下使用。 7839 7840**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7841 7842**返回值:** 7843 7844| 类型 | 说明 | 7845| ----------------- | --------------------------------- | 7846| [Window](#window) | 返回当前WindowStage下的主窗口对象。 | 7847 7848**错误码:** 7849 7850以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 7851 7852| 错误码ID | 错误信息 | 7853| ------- | ------------------------------ | 7854| 1300002 | This window state is abnormal. | 7855| 1300005 | This window stage is abnormal. | 7856 7857**示例:** 7858 7859```ts 7860import UIAbility from '@ohos.app.ability.UIAbility'; 7861import window from '@ohos.window'; 7862 7863export default class EntryAbility extends UIAbility { 7864 // ... 7865 7866 onWindowStageCreate(windowStage: window.WindowStage) { 7867 console.log('onWindowStageCreate'); 7868 try { 7869 let windowClass = windowStage.getMainWindowSync(); 7870 } catch (exception) { 7871 console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(exception)); 7872 } 7873 } 7874}; 7875``` 7876 7877### createSubWindow<sup>9+</sup> 7878 7879createSubWindow(name: string, callback: AsyncCallback<Window>): void 7880 7881创建该WindowStage实例下的子窗口,使用callback异步回调。 7882 7883**模型约束:** 此接口仅可在Stage模型下使用。 7884 7885**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7886 7887**参数:** 7888 7889| 参数名 | 类型 | 必填 | 说明 | 7890| -------- | -------------------------------------- | ---- | --------------------------------------------- | 7891| name | string | 是 | 子窗口的名字。 | 7892| callback | AsyncCallback<[Window](#window)> | 是 | 回调函数。返回当前WindowStage下的子窗口对象。 | 7893 7894**错误码:** 7895 7896以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 7897 7898| 错误码ID | 错误信息 | 7899| ------- | ------------------------------ | 7900| 1300002 | This window state is abnormal. | 7901| 1300005 | This window stage is abnormal. | 7902 7903**示例:** 7904 7905```ts 7906import UIAbility from '@ohos.app.ability.UIAbility'; 7907import window from '@ohos.window'; 7908import { BusinessError } from '@ohos.base'; 7909 7910export default class EntryAbility extends UIAbility { 7911 // ... 7912 7913 onWindowStageCreate(windowStage: window.WindowStage) { 7914 console.log('onWindowStageCreate'); 7915 let windowClass: window.Window | undefined = undefined; 7916 try { 7917 windowStage.createSubWindow('mySubWindow', (err: BusinessError, data) => { 7918 const errCode: number = err.code; 7919 if (errCode) { 7920 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 7921 return; 7922 } 7923 windowClass = data; 7924 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7925 if (!windowClass) { 7926 console.info('Failed to load the content. Cause: windowClass is null'); 7927 } 7928 else { 7929 (windowClass as window.Window).resize(500, 1000); 7930 } 7931 }); 7932 7933 } catch (exception) { 7934 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 7935 } 7936 } 7937}; 7938``` 7939 7940### createSubWindow<sup>9+</sup> 7941 7942createSubWindow(name: string): Promise<Window> 7943 7944创建该WindowStage实例下的子窗口,使用Promise异步回调。 7945 7946**模型约束:** 此接口仅可在Stage模型下使用。 7947 7948**系统能力:** SystemCapability.WindowManager.WindowManager.Core 7949 7950**参数:** 7951 7952| 参数名 | 类型 | 必填 | 说明 | 7953| ------ | ------ | ---- | -------------- | 7954| name | string | 是 | 子窗口的名字。 | 7955 7956**返回值:** 7957 7958| 类型 | 说明 | 7959| -------------------------------- | ------------------------------------------------ | 7960| Promise<[Window](#window)> | Promise对象。返回当前WindowStage下的子窗口对象。 | 7961 7962**错误码:** 7963 7964以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 7965 7966| 错误码ID | 错误信息 | 7967| ------- | ------------------------------ | 7968| 1300002 | This window state is abnormal. | 7969| 1300005 | This window stage is abnormal. | 7970 7971**示例:** 7972 7973```ts 7974import UIAbility from '@ohos.app.ability.UIAbility'; 7975import window from '@ohos.window'; 7976import { BusinessError } from '@ohos.base'; 7977 7978export default class EntryAbility extends UIAbility { 7979 // ... 7980 7981 onWindowStageCreate(windowStage: window.WindowStage) { 7982 console.log('onWindowStageCreate'); 7983 let windowClass: window.Window | undefined = undefined; 7984 try { 7985 let promise = windowStage.createSubWindow('mySubWindow'); 7986 promise.then((data) => { 7987 windowClass = data; 7988 console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data)); 7989 }).catch((err: BusinessError) => { 7990 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); 7991 }); 7992 } catch (exception) { 7993 console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(exception)); 7994 } 7995 } 7996}; 7997``` 7998 7999### getSubWindow<sup>9+</sup> 8000 8001getSubWindow(callback: AsyncCallback<Array<Window>>): void 8002 8003获取该WindowStage实例下的所有子窗口,使用callback异步回调。 8004 8005**模型约束:** 此接口仅可在Stage模型下使用。 8006 8007**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8008 8009**参数:** 8010 8011| 参数名 | 类型 | 必填 | 说明 | 8012| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- | 8013| callback | AsyncCallback<Array<[Window](#window)>> | 是 | 回调函数。返回当前WindowStage下的所有子窗口对象。 | 8014 8015**错误码:** 8016 8017以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8018 8019| 错误码ID | 错误信息 | 8020| ------- | ------------------------------ | 8021| 1300005 | This window stage is abnormal. | 8022 8023**示例:** 8024 8025```ts 8026import UIAbility from '@ohos.app.ability.UIAbility'; 8027import window from '@ohos.window'; 8028import { BusinessError } from '@ohos.base'; 8029 8030export default class EntryAbility extends UIAbility { 8031 // ... 8032 8033 onWindowStageCreate(windowStage: window.WindowStage) { 8034 console.log('onWindowStageCreate'); 8035 let windowClass: window.Window[] = []; 8036 windowStage.getSubWindow((err: BusinessError, data) => { 8037 const errCode: number = err.code; 8038 if (errCode) { 8039 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 8040 return; 8041 } 8042 windowClass = data; 8043 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 8044 }); 8045 } 8046}; 8047``` 8048 8049### getSubWindow<sup>9+</sup> 8050 8051getSubWindow(): Promise<Array<Window>> 8052 8053获取该WindowStage实例下的所有子窗口,使用Promise异步回调。 8054 8055**模型约束:** 此接口仅可在Stage模型下使用。 8056 8057**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8058 8059**返回值:** 8060 8061| 类型 | 说明 | 8062| --------------------------------------------- | ---------------------------------------------------- | 8063| Promise<Array<[Window](#window)>> | Promise对象。返回当前WindowStage下的所有子窗口对象。 | 8064 8065**错误码:** 8066 8067以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8068 8069| 错误码ID | 错误信息 | 8070| ------- | ------------------------------ | 8071| 1300005 | This window stage is abnormal. | 8072 8073**示例:** 8074 8075```ts 8076import UIAbility from '@ohos.app.ability.UIAbility'; 8077import window from '@ohos.window'; 8078import { BusinessError } from '@ohos.base'; 8079 8080export default class EntryAbility extends UIAbility { 8081 // ... 8082 8083 onWindowStageCreate(windowStage: window.WindowStage) { 8084 console.log('onWindowStageCreate'); 8085 let windowClass: window.Window[] = []; 8086 let promise = windowStage.getSubWindow(); 8087 promise.then((data) => { 8088 windowClass = data; 8089 console.info('Succeeded in obtaining the subwindow. Data: ' + JSON.stringify(data)); 8090 }).catch((err: BusinessError) => { 8091 console.error('Failed to obtain the subwindow. Cause: ' + JSON.stringify(err)); 8092 }) 8093 } 8094}; 8095``` 8096 8097### loadContent<sup>9+</sup> 8098 8099loadContent(path: string, storage: LocalStorage, callback: AsyncCallback<void>): void 8100 8101为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用callback异步回调。 8102 8103**模型约束:** 此接口仅可在Stage模型下使用。 8104 8105**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8106 8107**参数:** 8108 8109| 参数名 | 类型 | 必填 | 说明 | 8110| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 8111| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 8112| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 是 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 8113| callback | AsyncCallback<void> | 是 | 回调函数。 | 8114 8115**错误码:** 8116 8117以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8118 8119| 错误码ID | 错误信息 | 8120| ------- | ------------------------------ | 8121| 1300002 | This window state is abnormal. | 8122| 1300005 | This window stage is abnormal. | 8123 8124**示例:** 8125 8126```ts 8127import UIAbility from '@ohos.app.ability.UIAbility'; 8128import window from '@ohos.window'; 8129import { BusinessError } from '@ohos.base'; 8130 8131export default class EntryAbility extends UIAbility { 8132 // ... 8133 8134 storage: LocalStorage = new LocalStorage(); 8135 8136 onWindowStageCreate(windowStage: window.WindowStage) { 8137 this.storage.setOrCreate('storageSimpleProp', 121); 8138 console.log('onWindowStageCreate'); 8139 try { 8140 windowStage.loadContent('pages/page2', this.storage, (err: BusinessError) => { 8141 const errCode: number = err.code; 8142 if (errCode) { 8143 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 8144 return; 8145 } 8146 console.info('Succeeded in loading the content.'); 8147 }); 8148 } catch (exception) { 8149 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 8150 } 8151 } 8152}; 8153``` 8154 8155### loadContent<sup>9+</sup> 8156 8157loadContent(path: string, storage?: LocalStorage): Promise<void> 8158 8159为当前WindowStage的主窗口加载具体页面内容,通过LocalStorage传递状态属性给加载的页面,使用Promise异步回调。 8160 8161**模型约束:** 此接口仅可在Stage模型下使用。 8162 8163**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8164 8165**参数:** 8166 8167| 参数名 | 类型 | 必填 | 说明 | 8168| ------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 8169| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 8170| storage | [LocalStorage](../../quick-start/arkts-localstorage.md) | 否 | 页面级UI状态存储单元,这里用于为加载到窗口的页面内容传递状态属性。 | 8171 8172**返回值:** 8173 8174| 类型 | 说明 | 8175| ------------------- | ------------------------- | 8176| Promise<void> | 无返回结果的Promise对象。 | 8177 8178**错误码:** 8179 8180以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8181 8182| 错误码ID | 错误信息 | 8183| ------- | ------------------------------ | 8184| 1300002 | This window state is abnormal. | 8185| 1300005 | This window stage is abnormal. | 8186 8187**示例:** 8188 8189```ts 8190import UIAbility from '@ohos.app.ability.UIAbility'; 8191import window from '@ohos.window'; 8192import { BusinessError } from '@ohos.base'; 8193 8194export default class EntryAbility extends UIAbility { 8195 // ... 8196 8197 storage: LocalStorage = new LocalStorage(); 8198 8199 onWindowStageCreate(windowStage: window.WindowStage) { 8200 this.storage.setOrCreate('storageSimpleProp', 121); 8201 console.log('onWindowStageCreate'); 8202 try { 8203 let promise = windowStage.loadContent('pages/page2', this.storage); 8204 promise.then(() => { 8205 console.info('Succeeded in loading the content.'); 8206 }).catch((err: BusinessError) => { 8207 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 8208 }); 8209 } catch (exception) { 8210 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 8211 } 8212 ; 8213 } 8214}; 8215``` 8216 8217### loadContent<sup>9+</sup> 8218 8219loadContent(path: string, callback: AsyncCallback<void>): void 8220 8221为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。 8222 8223**模型约束:** 此接口仅可在Stage模型下使用。 8224 8225**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8226 8227**参数:** 8228 8229| 参数名 | 类型 | 必填 | 说明 | 8230| -------- | ------------------------- | ---- | -------------------- | 8231| path | string | 是 | 要加载到窗口中的页面内容的路径,该路径需添加到工程的main_pages.json文件中。 | 8232| callback | AsyncCallback<void> | 是 | 回调函数。 | 8233 8234**错误码:** 8235 8236以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8237 8238| 错误码ID | 错误信息 | 8239| ------- | ------------------------------ | 8240| 1300002 | This window state is abnormal. | 8241| 1300005 | This window stage is abnormal. | 8242 8243**示例:** 8244 8245```ts 8246import UIAbility from '@ohos.app.ability.UIAbility'; 8247import window from '@ohos.window'; 8248import { BusinessError } from '@ohos.base'; 8249 8250export default class EntryAbility extends UIAbility { 8251 // ... 8252 8253 onWindowStageCreate(windowStage: window.WindowStage) { 8254 console.log('onWindowStageCreate'); 8255 try { 8256 windowStage.loadContent('pages/page2', (err: BusinessError) => { 8257 const errCode: number = err.code; 8258 if (errCode) { 8259 console.error('Failed to load the content. Cause:' + JSON.stringify(err)); 8260 return; 8261 } 8262 console.info('Succeeded in loading the content.'); 8263 }); 8264 } catch (exception) { 8265 console.error('Failed to load the content. Cause:' + JSON.stringify(exception)); 8266 } 8267 } 8268}; 8269``` 8270 8271### on('windowStageEvent')<sup>9+</sup> 8272 8273on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void 8274 8275开启WindowStage生命周期变化的监听。 8276 8277**模型约束:** 此接口仅可在Stage模型下使用。 8278 8279**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8280 8281**参数:** 8282 8283| 参数名 | 类型 | 必填 | 说明 | 8284| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 8285| type | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 8286| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 是 | 回调函数。返回当前的WindowStage生命周期状态。 | 8287 8288**错误码:** 8289 8290以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8291 8292| 错误码ID | 错误信息 | 8293| ------- | ------------------------------ | 8294| 1300002 | This window state is abnormal. | 8295| 1300005 | This window stage is abnormal. | 8296 8297**示例:** 8298 8299```ts 8300import UIAbility from '@ohos.app.ability.UIAbility'; 8301import window from '@ohos.window'; 8302 8303export default class EntryAbility extends UIAbility { 8304 // ... 8305 8306 onWindowStageCreate(windowStage: window.WindowStage) { 8307 console.log('onWindowStageCreate'); 8308 try { 8309 windowStage.on('windowStageEvent', (data) => { 8310 console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + 8311 JSON.stringify(data)); 8312 }); 8313 } catch (exception) { 8314 console.error('Failed to enable the listener for window stage event changes. Cause:' + 8315 JSON.stringify(exception)); 8316 } 8317 } 8318}; 8319``` 8320 8321### off('windowStageEvent')<sup>9+</sup> 8322 8323off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void 8324 8325关闭WindowStage生命周期变化的监听。 8326 8327**模型约束:** 此接口仅可在Stage模型下使用。 8328 8329**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8330 8331**参数:** 8332 8333| 参数名 | 类型 | 必填 | 说明 | 8334| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 8335| type | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 | 8336| callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 否 | 回调函数。返回当前的WindowStage生命周期状态。若传入参数,则关闭该监听。若未传入参数,则关闭所有WindowStage生命周期变化的监听。 | 8337 8338**错误码:** 8339 8340以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8341 8342| 错误码ID | 错误信息 | 8343| ------- | ------------------------------ | 8344| 1300002 | This window state is abnormal. | 8345| 1300005 | This window stage is abnormal. | 8346 8347**示例:** 8348 8349```ts 8350import UIAbility from '@ohos.app.ability.UIAbility'; 8351import window from '@ohos.window'; 8352 8353export default class EntryAbility extends UIAbility { 8354 // ... 8355 8356 onWindowStageCreate(windowStage: window.WindowStage) { 8357 console.log('onWindowStageCreate'); 8358 try { 8359 windowStage.off('windowStageEvent'); 8360 } catch (exception) { 8361 console.error('Failed to disable the listener for window stage event changes. Cause:' + 8362 JSON.stringify(exception)); 8363 } 8364 } 8365}; 8366``` 8367 8368### disableWindowDecor()<sup>9+</sup> 8369 8370disableWindowDecor(): void 8371 8372禁止窗口装饰。 8373 8374**模型约束:** 此接口仅可在Stage模型下使用。 8375 8376**系统接口:** 此接口为系统接口。 8377 8378**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8379 8380**错误码:** 8381 8382以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8383 8384| 错误码ID | 错误信息 | 8385| ------- | ------------------------------ | 8386| 1300002 | This window state is abnormal. | 8387| 1300005 | This window stage is abnormal. | 8388 8389**示例:** 8390 8391```ts 8392import UIAbility from '@ohos.app.ability.UIAbility'; 8393import window from '@ohos.window'; 8394 8395export default class EntryAbility extends UIAbility { 8396 // ... 8397 8398 onWindowStageCreate(windowStage: window.WindowStage) { 8399 console.log('disableWindowDecor'); 8400 windowStage.disableWindowDecor(); 8401 } 8402}; 8403``` 8404 8405### setShowOnLockScreen()<sup>9+</sup> 8406 8407setShowOnLockScreen(showOnLockScreen: boolean): void 8408 8409设置应用显示在锁屏之上。 8410 8411**系统接口:** 此接口为系统接口。 8412 8413**模型约束:** 此接口仅可在Stage模型下使用。 8414 8415**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8416 8417**参数:** 8418 8419| 参数名 | 类型 | 必填 | 说明 | 8420| ---------------- | ------- | ---- | ---------------------------- | 8421| showOnLockScreen | boolean | 是 | 是否设置应用显示在锁屏之上。true表示显示在锁屏之上;false表示不显示在锁屏之上。 | 8422 8423**错误码:** 8424 8425以下错误码的详细介绍请参见[窗口错误码](../errorcodes/errorcode-window.md)。 8426 8427| 错误码ID | 错误信息 | 8428| ------- | ------------------------------ | 8429| 1300002 | This window state is abnormal. | 8430| 1300005 | This window stage is abnormal. | 8431 8432**示例:** 8433 8434```ts 8435import UIAbility from '@ohos.app.ability.UIAbility'; 8436import window from '@ohos.window'; 8437 8438export default class EntryAbility extends UIAbility { 8439 // ... 8440 8441 onWindowStageCreate(windowStage: window.WindowStage) { 8442 console.log('onWindowStageCreate'); 8443 try { 8444 windowStage.setShowOnLockScreen(true); 8445 } catch (exception) { 8446 console.error('Failed to show on lockscreen. Cause:' + JSON.stringify(exception)); 8447 } 8448 } 8449}; 8450``` 8451 8452## TransitionContext<sup>9+</sup> 8453 8454属性转换的上下文信息。 8455 8456### 属性 8457 8458**系统接口:** 此接口为系统接口。 8459 8460**系统能力**:SystemCapability.WindowManager.WindowManager.Core 8461 8462| 名称 | 类型 | 可读 | 可写 | 说明 | 8463| --------------------- | ----------------- | ---- | ---- | ---------------- | 8464| toWindow<sup>9+</sup> | [Window](#window) | 是 | 是 | 动画的目标窗口。 | 8465 8466### completeTransition<sup>9+</sup> 8467 8468completeTransition(isCompleted: boolean): void 8469 8470设置属性转换的最终完成状态。该函数需要在动画函数[animateTo()](../arkui-ts/ts-explicit-animation.md)执行后设置。 8471 8472**系统接口:** 此接口为系统接口。 8473 8474**系统能力**:SystemCapability.WindowManager.WindowManager.Core 8475 8476**参数:** 8477 8478| 参数名 | 类型 | 必填 | 说明 | 8479| ----------- | ------- | ---- | ------------------------------------------------------------ | 8480| isCompleted | boolean | 是 | 窗口属性转换是否完成。true表示完成本次转换;false表示撤销本次转换。 | 8481 8482**示例:** 8483 8484```ts 8485(context: window.TransitionContext) => { 8486 let toWindow: window.Window = context.toWindow; 8487 animateTo({ 8488 duration: 1000, // 动画时长 8489 tempo: 0.5, // 播放速率 8490 curve: Curve.EaseInOut, // 动画曲线 8491 delay: 0, // 动画延迟 8492 iterations: 1, // 播放次数 8493 playMode: PlayMode.Normal, // 动画模式 8494 }, () => { 8495 let obj: window.TranslateOptions = { 8496 x: 100.0, 8497 y: 0.0, 8498 z: 0.0 8499 }; 8500 toWindow.translate(obj); 8501 console.info('toWindow translate end'); 8502 } 8503 ); 8504 try { 8505 context.completeTransition(true) 8506 } catch (exception) { 8507 console.info('toWindow translate fail. Cause: ' + JSON.stringify(exception)); 8508 } 8509 console.info('complete transition end'); 8510}; 8511``` 8512 8513## TransitionController<sup>9+</sup> 8514 8515属性转换控制器。使用其子接口之前得先创建系统窗口,参照示例代码。 8516 8517**系统接口:** 此接口为系统接口。 8518 8519**示例:** 8520 8521```ts 8522import { BusinessError } from '@ohos.base'; 8523 8524let windowClass: window.Window | undefined = undefined; 8525let config: window.Configuration = { 8526 name: "systemTypeWindow", 8527 windowType: window.WindowType.TYPE_PANEL, //根据需要自选系统窗口类型 8528 ctx: this.context 8529}; 8530try { 8531 let promise = window.createWindow(config); 8532 promise.then((data) => { 8533 windowClass = data; 8534 console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); 8535 }).catch((err: BusinessError) => { 8536 console.error('Failed to create the Window. Cause:' + JSON.stringify(err)); 8537 }); 8538} catch (exception) { 8539 console.error('Failed to create the window. Cause: ' + JSON.stringify(exception)); 8540} 8541``` 8542 8543### animationForShown<sup>9+</sup> 8544 8545animationForShown(context: TransitionContext): void 8546 8547窗口显示时的自定义动画配置。 8548 8549**系统接口:** 此接口为系统接口。 8550 8551**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8552 8553**参数:** 8554 8555| 参数名 | 类型 | 必填 | 说明 | 8556| ------- | ---------------------------------------- | ---- | -------------------- | 8557| context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | 8558 8559**示例:** 8560 8561```ts 8562// xxx.ts 8563export class AnimationConfig { 8564 private animationForShownCallFunc_: Function = undefined; 8565 ShowWindowWithCustomAnimation(windowClass: window.Window, callback) { 8566 if (!windowClass) { 8567 console.error('windowClass is undefined'); 8568 return false; 8569 } 8570 this.animationForShownCallFunc_ = callback; 8571 let controller: window.TransitionController = windowClass.getTransitionController(); 8572 controller.animationForShown = (context : window.TransitionContext)=> { 8573 this.animationForShownCallFunc_(context); 8574 }; 8575 windowClass.showWithAnimation(()=>{ 8576 console.info('Show with animation success'); 8577 }) 8578 } 8579} 8580``` 8581 8582```ts 8583// xxx.ets 8584let animationConfig = new AnimationConfig(); 8585let systemTypeWindow = window.findWindow("systemTypeWindow"); // 此处需要获取一个系统类型窗口。 8586try { 8587 animationConfig?.ShowWindowWithCustomAnimation(systemTypeWindow, (context : window.TransitionContext)=>{ 8588 console.info('complete transition end'); 8589 let toWindow = context.toWindow; 8590 animateTo({ 8591 duration: 1000, // 动画时长 8592 tempo: 0.5, // 播放速率 8593 curve: Curve.EaseInOut, // 动画曲线 8594 delay: 0, // 动画延迟 8595 iterations: 1, // 播放次数 8596 playMode: PlayMode.Normal, // 动画模式 8597 onFinish: () => { 8598 console.info('onFinish in animation'); 8599 context.completeTransition(true) 8600 } 8601 }, () => { 8602 let obj : window.TranslateOptions = { 8603 x : 100.0, 8604 y : 0.0, 8605 z : 0.0 8606 }; 8607 toWindow.translate(obj); // 设置动画过程中的属性转换 8608 console.info('toWindow translate end in animation'); 8609 }); 8610 console.info('complete transition end'); 8611 }); 8612} catch (error) { 8613 console.error('ShowWindowWithCustomAnimation err : ' + JSON.stringify(error)); 8614} 8615``` 8616 8617### animationForHidden<sup>9+</sup> 8618 8619animationForHidden(context: TransitionContext): void 8620 8621窗口隐藏时的自定义动画配置。 8622 8623**系统接口:** 此接口为系统接口。 8624 8625**系统能力:** SystemCapability.WindowManager.WindowManager.Core 8626 8627**参数:** 8628 8629| 参数名 | 类型 | 必填 | 说明 | 8630| ------- | ---------------------------------------- | ---- | -------------------- | 8631| context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | 8632 8633**示例:** 8634```ts 8635// xxx.ts 8636export class AnimationConfig { 8637 private animationForHiddenCallFunc_: Function = undefined; 8638 HideWindowWithCustomAnimation(windowClass: window.Window, callback) { 8639 if (!windowClass) { 8640 console.error('windowClass is undefined'); 8641 return false; 8642 } 8643 this.animationForHiddenCallFunc_ = callback; 8644 let controller: window.TransitionController = windowClass.getTransitionController(); 8645 controller.animationForHidden = (context : window.TransitionContext)=> { 8646 this.animationForHiddenCallFunc_(context); 8647 }; 8648 windowClass.hideWithAnimation(()=>{ 8649 console.info('hide with animation success'); 8650 }) 8651 } 8652} 8653``` 8654 8655```ts 8656// xxx.ets 8657let animationConfig = new AnimationConfig(); 8658let systemTypeWindow = window.findWindow("systemTypeWindow"); // 此处需要获取一个系统类型窗口。 8659try { 8660 animationConfig?.HideWindowWithCustomAnimation(systemTypeWindow, (context : window.TransitionContext)=>{ 8661 console.info('complete transition end'); 8662 let toWindow = context.toWindow; 8663 animateTo({ 8664 duration: 1000, // 动画时长 8665 tempo: 0.5, // 播放速率 8666 curve: Curve.EaseInOut, // 动画曲线 8667 delay: 0, // 动画延迟 8668 iterations: 1, // 播放次数 8669 playMode: PlayMode.Normal, // 动画模式 8670 onFinish: () => { 8671 console.info('onFinish in animation'); 8672 context.completeTransition(true) 8673 } 8674 }, () => { 8675 let obj : window.TranslateOptions = { 8676 x : 100.0, 8677 y : 0.0, 8678 z : 0.0 8679 }; 8680 toWindow.translate(obj); // 设置动画过程中的属性转换 8681 console.info('toWindow translate end in animation'); 8682 }); 8683 console.info('complete transition end'); 8684 }); 8685} catch (error) { 8686 console.error('HideWindowWithCustomAnimation err : ' + JSON.stringify(error)); 8687} 8688``` 8689