# @ohos.window (窗口)(系统接口) 窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。 该模块提供以下窗口相关的常用功能: - [Window](#window):当前窗口实例,窗口管理器管理的基本单元。 - [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。 > **说明:** > > - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > > - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.window (窗口)](js-apis-window.md)。 ## 导入模块 ```ts import { window } from '@kit.ArkUI'; ``` ## WindowType7+ 窗口类型枚举。 | 名称 | 值 | 说明 | |-------------------------------------| ------ |----------------------------------------------------------------------------------------| | TYPE_INPUT_METHOD(deprecated) | 2 | 表示输入法窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**说明:** 从API version 9开始支持,从API version 13开始废弃,无替代窗口类型,输入法相关控制都请调用[输入法框架侧接口](../../inputmethod/inputmethod-application-guide.md)执行。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_STATUS_BAR9+ | 3 | 表示状态栏窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_PANEL9+ | 4 | 表示通知栏。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_KEYGUARD9+ | 5 | 表示锁屏。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_VOLUME_OVERLAY9+ | 6 | 表示音量条。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_NAVIGATION_BAR9+ | 7 | 表示导航栏窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_WALLPAPER9+ | 9 | 表示壁纸。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_DESKTOP9+ | 10 | 表示桌面。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_LAUNCHER_RECENT9+ | 11 | 表示多任务中心。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_LAUNCHER_DOCK9+ | 12 | 表示桌面Dock栏。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_VOICE_INTERACTION9+ | 13 | 表示智慧语音。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_POINTER9+ | 14 | 表示鼠标。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_FLOAT_CAMERA9+ | 15 | 表示相机类型悬浮窗。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_SCREENSHOT9+ | 17 | 表示截屏窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_SYSTEM_TOAST11+ | 18 | 表示顶层提示窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_DIVIDER11+ | 19 | 表示分屏条。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_GLOBAL_SEARCH11+ | 20 | 表示全局搜索窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core | | TYPE_HANDWRITE12+ | 21 | 表示手写笔窗口。
**模型约束:** 此接口仅可在Stage模型下使用。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.Window.SessionManager | ## WindowMode7+ 窗口模式枚举。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core | 名称 | 值 | 说明 | | ---------- | ---- | ----------------------------- | | UNDEFINED | 1 | 表示APP未定义窗口模式。 | | FULLSCREEN | 2 | 表示APP全屏模式。 | | PRIMARY | 3 | 表示APP分屏多窗口主要模式。 | | SECONDARY | 4 | 表示APP分屏多窗口次要模式。 | | FLOATING | 5 | 表示APP自由悬浮形式窗口模式。 | ## WindowLayoutMode9+ 窗口布局模式枚举。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core | 名称 | 值 | 说明 | | ---------- | ---- | ----------------------------- | | WINDOW_LAYOUT_MODE_CASCADE | 0 | 表示使用层叠布局模式。 | | WINDOW_LAYOUT_MODE_TILE | 1 | 表示使用平铺布局模式。 | ## BlurStyle9+ 窗口模糊类型枚举。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core | 名称 | 值 | 说明 | | ------- | ---- | -------------------- | | OFF | 0 | 表示关闭模糊。 | | THIN | 1 | 表示较薄的模糊类型。 | | REGULAR | 2 | 表示适中的模糊类型。 | | THICK | 3 | 表示较厚的模糊类型。 | ## SystemBarRegionTint8+ 单个导航栏或状态栏回调信息。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core | 名称 | 类型 | 可读 | 可写 | 说明 | | --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | | type | [WindowType](#windowtype7) | 是 | 否 | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 | | isEnable | boolean | 是 | 否 | 当前系统栏是否显示。true表示显示;false表示不显示。 | | region | [Rect](js-apis-window.md#rect7) | 是 | 否 | 当前系统栏的位置及大小。 | | backgroundColor | string | 是 | 否 | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | | contentColor | string | 是 | 否 | 系统栏文字颜色。 | ## SystemBarTintState8+ 当前系统栏回调信息集合。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core | 名称 | 类型 | 可读 | 可写 | 说明 | | ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- | | displayId | number | 是 | 否 | 当前物理屏幕id,该参数应为整数。 | | regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | 否 | 当前已改变的所有系统栏信息。 | ## ScaleOptions9+ 缩放参数。 **系统接口:** 此接口为系统接口。 **系统能力**:SystemCapability.WindowManager.WindowManager.Core | 名称 | 类型 | 只读 | 必填 | 说明 | | ------ | -------- | ---- | ---- | --------------------------------------------| | x | number | 否 | 否 | X轴的缩放参数。该参数为浮点数,默认值为1.0。 | | y | number | 否 | 否 | Y轴的缩放参数。该参数为浮点数,默认值为1.0。 | | pivotX | number | 否 | 否 | 缩放中心点X轴坐标。该参数为浮点数,默认值为0.5, 取值范围[0.0, 1.0]。 | | pivotY | number | 否 | 否 | 缩放中心点Y轴坐标。该参数为浮点数,默认值为0.5, 取值范围[0.0, 1.0]。 | ## RotateOptions9+ 旋转参数。 **系统接口:** 此接口为系统接口。 **系统能力**:SystemCapability.WindowManager.WindowManager.Core | 名称 | 类型 | 只读 | 必填 | 说明 | | ------ | -------- | ---- |---- |---------------------------------------------| | x | number | 否 | 否 | 绕X轴的旋转角度。该参数为浮点数,默认值为0.0。 | | y | number | 否 | 否 | 绕Y轴的旋转角度。该参数为浮点数,默认值为0.0。 | | z | number | 否 | 否 | 绕Z轴的旋转角度。该参数为浮点数,默认值为0.0。 | | pivotX | number | 否 | 否 | 旋转中心点X轴坐标。该参数为浮点数,默认值为0.5, 取值范围为[0.0, 1.0]。 | | pivotY | number | 否 | 否 | 旋转中心点Y轴坐标。该参数为浮点数,默认值为0.5, 取值范围为[0.0, 1.0]。 | ## TranslateOptions9+ 平移参数。 **系统接口:** 此接口为系统接口。 **系统能力**:SystemCapability.WindowManager.WindowManager.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ---- | -------- | ---- | ---- | ---------------------------- | | x | number | 否 | 是 | X轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | | y | number | 否 | 是 | Y轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | | z | number | 否 | 是 | Z轴的平移参数。该参数为浮点数,默认值为0.0,单位为px。 | ## WindowInfo12+ 当前窗口的详细信息。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager | 名称 | 类型 | 只读 | 可选 | 说明 | | ------ | ------ | ---- | ---- | ------------------------------------------ | | rect | [Rect](js-apis-window.md#rect7) | 是 | 否 | 窗口内可绘制区域尺寸,其中左边界上边界是相对窗口计算。 | | bundleName | string | 是 | 否 | 应用Bundle的名称。 | | abilityName | string | 是 | 否 | Ability的名称。 | | windowId | number | 是 | 否 | 窗口ID。 | | windowStatusType | [WindowStatusType](js-apis-window.md#windowstatustype11) | 是 | 否 | 窗口模式枚举。 | | isFocused14+ | boolean | 是 | 是 | 窗口是否获焦。true表示窗口获焦;false表示窗口未获焦。 | ## window.minimizeAll9+ minimizeAll(id: number, callback: AsyncCallback<void>): void 最小化某显示设备下的所有窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号,该参数仅支持整数输入。 | | callback | AsyncCallback<void> | 是 | 回调信息。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { display } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; let displayClass: display.Display | null = null; displayClass = display.getDefaultDisplaySync(); try { window.minimizeAll(displayClass.id, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to minimize all windows. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in minimizing all windows.'); }); } catch (exception) { console.error(`Failed to minimize all windows. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.minimizeAll9+ minimizeAll(id: number): Promise<void> 最小化某显示设备下的所有窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | id | number | 是 | 显示设备[Display](js-apis-display.md#display)的ID号,该参数仅支持整数输入。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { display } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; let displayClass: display.Display | null = null; displayClass = display.getDefaultDisplaySync(); try { let promise = window.minimizeAll(displayClass.id); promise.then(() => { console.info('Succeeded in minimizing all windows.'); }).catch((err: BusinessError) => { console.error(`Failed to minimize all windows. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to minimize all windows. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.toggleShownStateForAllAppWindows9+ toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void 多窗口快速切换时隐藏或者恢复应用窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | callback | AsyncCallback<void> | 是 | 回调信息。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; window.toggleShownStateForAllAppWindows((err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to toggle shown state for all app windows. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in toggling shown state for all app windows.'); }); ``` ## window.toggleShownStateForAllAppWindows9+ toggleShownStateForAllAppWindows(): Promise<void> 多窗口快速切换时隐藏或者恢复应用窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let promise = window.toggleShownStateForAllAppWindows(); promise.then(() => { console.info('Succeeded in toggling shown state for all app windows.'); }).catch((err: BusinessError) => { console.error(`Failed to toggle shown state for all app windows. Cause code: ${err.code}, message: ${err.message}`); }); ``` ## window.setWindowLayoutMode9+ setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void 设置窗口布局模式。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | | callback | AsyncCallback<void> | 是 | 回调信息。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to set window layout mode. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in setting window layout mode.'); }); } catch (exception) { console.error(`Failed to set window layout mode. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.setWindowLayoutMode9+ setWindowLayoutMode(mode: WindowLayoutMode): Promise<void> 设置窗口布局模式。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | mode | [WindowLayoutMode](#windowlayoutmode9) | 是 | 设置的窗口布局模式。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let promise = window.setWindowLayoutMode(window.WindowLayoutMode.WINDOW_LAYOUT_MODE_CASCADE); promise.then(() => { console.info('Succeeded in setting window layout mode.'); }).catch((err: BusinessError) => { console.error(`Failed to set window layout mode. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to set window layout mode. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.on('systemBarTintChange')8+ on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void 开启状态栏、导航栏属性变化的监听。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | | callback | Callback<[SystemBarTintState](#systembartintstate8)> | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **示例:** ```ts try { window.on('systemBarTintChange', (data) => { console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data)); }); } catch (exception) { console.error(`Failed to enable the listener for systemBarTint changes. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.off('systemBarTintChange')8+ off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void 关闭状态栏、导航栏属性变化的监听。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | | callback | Callback<[SystemBarTintState](#systembartintstate8)> | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有状态栏、导航栏属性变化的监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | **示例:** ```ts const callback = (systemBarTintState: window.SystemBarTintState) => { // ... } try { window.on('systemBarTintChange', callback); window.off('systemBarTintChange', callback); // 如果通过on开启多个callback进行监听,同时关闭所有监听: window.off('systemBarTintChange'); } catch (exception) { console.error(`Failed to enable or disable the listener for systemBarTint changes. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.on('gestureNavigationEnabledChange')10+ on(type: 'gestureNavigationEnabledChange', callback: Callback<boolean>): void 添加手势导航启用状态变化的监听。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | | type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 | | callback | Callback<boolean> | 是 | 回调函数。返回当前手势导航的启用状态。true表示手势导航状态变化为启用;false表示手势导航状态变化为禁用。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts try { window.on('gestureNavigationEnabledChange', (data) => { console.info('Succeeded in enabling the listener for gesture navigation status changes. Data: ' + JSON.stringify(data)); }); } catch (exception) { console.error(`Failed to enable the listener for gesture navigation status changes. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.off('gestureNavigationEnabledChange')10+ off(type: 'gestureNavigationEnabledChange', callback?: Callback<boolean>): void 移除手势导航启用状态变化的监听。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ----------------------- | -- | ------------------------------------------------------------ | | type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 | | callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有手势导航启用状态变化的监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts const callback = (bool: boolean) => { // ... } try { window.on('gestureNavigationEnabledChange', callback); window.off('gestureNavigationEnabledChange', callback); // 如果通过on开启多个callback进行监听,同时关闭所有监听: window.off('gestureNavigationEnabledChange'); } catch (exception) { console.error(`Failed to enable or disable the listener for gesture navigation status changes. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.on('waterMarkFlagChange')10+ on(type: 'waterMarkFlagChange', callback: Callback<boolean>): void 添加水印启用状态变化的监听。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ----------------------- | ---- | ----------------------------------------------------------------------------- | | type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 | | callback | Callback<boolean> | 是 | 回调函数。返回当前水印的启用状态。true表示当前已启用水印;false表示当前未启用水印。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts try { window.on('waterMarkFlagChange', (data) => { console.info('Succeeded in enabling the listener for watermark flag changes. Data: ' + JSON.stringify(data)); }); } catch (exception) { console.error(`Failed to enable the listener for watermark flag changes. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.off('waterMarkFlagChange')10+ off(type: 'waterMarkFlagChange', callback?: Callback<boolean>): void 移除水印启用状态变化的监听。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ----------------------- | -- | ------------------------------------------------------------ | | type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 | | callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有水印启用状态变化的监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Incorrect parameter types; 2. Parameter verification failed. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts const callback = (bool: boolean) => { // ... } try { window.on('waterMarkFlagChange', callback); window.off('waterMarkFlagChange', callback); // 如果通过on开启多个callback进行监听,同时关闭所有监听: window.off('waterMarkFlagChange'); } catch (exception) { console.error(`Failed to enable or disable the listener for watermark flag changes. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.setGestureNavigationEnabled10+ setGestureNavigationEnabled(enable: boolean, callback: AsyncCallback<void>): void 设置手势导航启用状态。使用callback异步回调。系统出于安全的考虑,不会干预手势的禁用和恢复。应用调用本接口禁用手势后异常退出的情况下,如果想要恢复手势,需自行实现自动拉起机制并再次调用本接口恢复手势。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 | | callback | AsyncCallback<void> | 是 | 回调信息。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | --------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { window.setGestureNavigationEnabled(true, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to set gesture navigation enabled. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in setting gesture navigation enabled.'); }); } catch (exception) { console.error(`Failed to set gesture navigation enabled. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.setGestureNavigationEnabled10+ setGestureNavigationEnabled(enable: boolean): Promise<void> 设置手势导航启用状态。使用Promise异步回调。系统出于安全的考虑,不会干预手势的禁用和恢复。应用调用本接口禁用手势后异常退出的情况下,如果想要恢复手势,需自行实现自动拉起机制并再次调用本接口恢复手势。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------- | ---- | -------------------- | | enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let promise = window.setGestureNavigationEnabled(true); promise.then(() => { console.info('Succeeded in setting gesture navigation enabled.'); }).catch((err: BusinessError) => { console.error(`Failed to set gesture navigation enabled. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to set gesture navigation enabled. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.setWaterMarkImage10+ setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean, callback: AsyncCallback<void>): void 设置水印图片显示状态。使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | -------------- | | pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 水印图片。 | | enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 | | callback | AsyncCallback<void> | 是 | 回调信息。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | --------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; let enable: boolean = true; let color: ArrayBuffer = new ArrayBuffer(0); let initializationOptions: image.InitializationOptions = { size: { height: 100, width: 100 } }; image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { console.info('Succeeded in creating pixelmap.'); try { window.setWaterMarkImage(pixelMap, enable, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to show watermark image. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in showing watermark image.'); }); } catch (exception) { console.error(`Failed to show watermark image. Cause code: ${exception.code}, message: ${exception.message}`); } }).catch((err: BusinessError) => { console.error(`Failed to create PixelMap. Cause code: ${err.code}, message: ${err.message}`); }); ``` ## window.setWaterMarkImage10+ setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean): Promise<void> 设置水印图片显示状态。使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | --------------------------- | ---- | -------------------- | | pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 水印图片。 | | enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; let enable: boolean = true; let color: ArrayBuffer = new ArrayBuffer(0); let initializationOptions: image.InitializationOptions = { size: { height: 100, width: 100 } }; image.createPixelMap(color, initializationOptions).then((pixelMap: image.PixelMap) => { console.info('Succeeded in creating pixelmap.'); try { let promise = window.setWaterMarkImage(pixelMap, enable); promise.then(() => { console.info('Succeeded in showing watermark image.'); }).catch((err: BusinessError) => { console.error(`Failed to show watermark image. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to show watermark image. Cause code: ${exception.code}, message: ${exception.message}`); } }).catch((err: BusinessError) => { console.error(`Failed to create PixelMap. Cause code: ${err.code}, message: ${err.message}`); }); ``` ## window.getSnapshot12+ getSnapshot(windowId: number): Promise 获取指定窗口相同尺寸截图,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ----- | ------------ | | windowId | number | 是 | 窗口Id。可通过[getWindowProperties](js-apis-window.md#getwindowproperties9)接口获取到相关窗口属性,其中属性id即对应为窗口ID。 | **返回值:** | 类型 | 说明 | | ----------------------- | ------------------------------- | | Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise对象。返回指定窗口截图。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | -------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | This operation is not accessible. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { image } from '@kit.ImageKit'; try { // 此处仅示意,请使用getWindowProperties获取对应窗口ID再进行使用 let windowId: number = 40; let promise = window.getSnapshot(windowId); promise.then((pixelMap: image.PixelMap) => { console.info('Succeeded in getting snapshot window. Pixel bytes number:' + pixelMap.getPixelBytesNumber()); pixelMap.release(); }).catch((err: BusinessError) =>{ console.error(`Failed to get snapshot. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to get snapshot. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ## window.getVisibleWindowInfo12+ getVisibleWindowInfo(): Promise<Array<WindowInfo>> 获取当前屏幕的可见窗口(未退至后台的窗口)信息。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **返回值:** | 类型 | 说明 | | ------------------- | ----------------------- | | Promise<[WindowInfo](#windowinfo12)> | Promise对象,返回当前可见窗口的相关信息。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed, non-system application uses system API. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; let promise = window.getVisibleWindowInfo(); promise.then((data) => { data.forEach(windowInfo=>{ console.info(`left:${windowInfo.rect.left}`); console.info(`top:${windowInfo.rect.top}`); console.info(`width:${windowInfo.rect.width}`); console.info(`height:${windowInfo.rect.height}`); console.info(`windowId:${windowInfo.windowId}`); console.info(`windowStatusType:${windowInfo.windowStatusType}`); console.info(`abilityName:${windowInfo.abilityName}`); console.info(`bundleName:${windowInfo.bundleName}`); console.info(`isFocused:${windowInfo.isFocused}`); }) }).catch((err: BusinessError) => { console.error('Failed to getWindowInfo. Cause: ' + JSON.stringify(err)); }); ``` ## Window 当前窗口实例,窗口管理器管理的基本单元。 下列API示例中都需先使用[getLastWindow()](js-apis-window.md#windowgetlastwindow9)、[createWindow()](js-apis-window.md#windowcreatewindow9)、[findWindow()](js-apis-window.md#windowfindwindow9)中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。 ### hide7+ hide (callback: AsyncCallback<void>): void 隐藏当前窗口,使用callback异步回调,仅支持系统窗口与应用子窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; windowClass.hide((err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to hide the window. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in hiding the window.'); }); ``` ### hide7+ hide(): Promise<void> 隐藏当前窗口,使用Promise异步回调,仅支持系统窗口与应用子窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let promise = windowClass.hide(); promise.then(() => { console.info('Succeeded in hiding the window.'); }).catch((err: BusinessError) => { console.error(`Failed to hide the window. Cause code: ${err.code}, message: ${err.message}`); }); ``` ### hideWithAnimation9+ hideWithAnimation(callback: AsyncCallback<void>): void 隐藏当前窗口,过程中播放动画,使用callback异步回调,仅支持系统窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; windowClass.hideWithAnimation((err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to hide the window with animation. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in hiding the window with animation.'); }); ``` ### hideWithAnimation9+ hideWithAnimation(): Promise<void> 隐藏当前窗口,过程中播放动画,使用Promise异步回调,仅支持系统窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let promise = windowClass.hideWithAnimation(); promise.then(() => { console.info('Succeeded in hiding the window with animation.'); }).catch((err: BusinessError) => { console.error(`Failed to hide the window with animation. Cause code: ${err.code}, message: ${err.message}`); }); ``` ### showWithAnimation9+ showWithAnimation(callback: AsyncCallback<void>): void 显示当前窗口,过程中播放动画,使用callback异步回调,仅支持系统窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; windowClass.showWithAnimation((err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to show the window with animation. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in showing the window with animation.'); }); ``` ### showWithAnimation9+ showWithAnimation(): Promise<void> 显示当前窗口,过程中播放动画,使用Promise异步回调,仅支持系统窗口。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let promise = windowClass.showWithAnimation(); promise.then(() => { console.info('Succeeded in showing the window with animation.'); }).catch((err: BusinessError) => { console.error(`Failed to show the window with animation. Cause code: ${err.code}, message: ${err.message}`); }); ``` ### setWindowMode9+ setWindowMode(mode: WindowMode, callback: AsyncCallback<void>): void 设置主窗口模式,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------- | -- | --------- | | mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; windowStage.getMainWindow((err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; let mode = window.WindowMode.FULLSCREEN; try { windowClass.setWindowMode(mode, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to set the window mode. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in setting the window mode.'); }); } catch (exception) { console.error(`Failed to set the window mode. Cause code: ${exception.code}, message: ${exception.message}`); } }); } } ``` ### setWindowMode9+ setWindowMode(mode: WindowMode): Promise<void> 设置主窗口模式,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------------------------- | -- | --------- | | mode | [WindowMode](#windowmode7) | 是 | 窗口模式。 | **返回值:** | 类型 | 说明 | | ------------------- | ----------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; windowStage.getMainWindow((err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; let mode = window.WindowMode.FULLSCREEN; try { let promise = windowClass.setWindowMode(mode); promise.then(() => { console.info('Succeeded in setting the window mode.'); }).catch((err: BusinessError) => { console.error(`Failed to set the window mode. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to set the window mode. Cause code: ${exception.code}, message: ${exception.message}`); } }); } } ``` ### bindDialogTarget9+ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | -------------------- | | token | [rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | | deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { rpc } from '@kit.IPCKit'; import { BusinessError } from '@kit.BasicServicesKit'; class MyDeathRecipient { onRemoteDied() { console.log('server died'); } } class TestRemoteObject extends rpc.RemoteObject { constructor(descriptor: string) { super(descriptor); } addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } isObjectDead(): boolean { return false; } } let token: TestRemoteObject = new TestRemoteObject('testObject'); let windowClass: window.Window | undefined = undefined; let config: window.Configuration = { name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; try { window.createWindow(config, (err: BusinessError, data) => { let errCode: number = err.code; if (errCode) { console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; }); windowClass.bindDialogTarget(token, () => { console.info('Dialog Window Need Destroy.'); }, (err: BusinessError) => { let errCode: number = err.code; if (errCode) { console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in binding dialog target.'); }); } catch (exception) { console.error(`Failed to bind dialog target. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### bindDialogTarget9+ bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void> 绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | -------------------- | | token | [rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) | 是 | 目标窗口token值。 | | deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { rpc } from '@kit.IPCKit'; import { BusinessError } from '@kit.BasicServicesKit'; class MyDeathRecipient { onRemoteDied() { console.log('server died'); } } class TestRemoteObject extends rpc.RemoteObject { constructor(descriptor: string) { super(descriptor); } addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean { return true; } isObjectDead(): boolean { return false; } } let token: TestRemoteObject = new TestRemoteObject('testObject'); let windowClass: window.Window | undefined = undefined; let config: window.Configuration = { name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; try { window.createWindow(config, (err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; }); let promise = windowClass.bindDialogTarget(token, () => { console.info('Dialog Window Need Destroy.'); }); promise.then(() => { console.info('Succeeded in binding dialog target.'); }).catch((err: BusinessError) => { console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to bind dialog target. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### bindDialogTarget9+ bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>, callback: AsyncCallback<void>): void 绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | -------------------- | | requestInfo | [dialogRequest.RequestInfo](../apis-ability-kit/js-apis-app-ability-dialogRequest.md#requestinfo) | 是 | 目标窗口RequestInfo值。 | | deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { dialogRequest, Want, ServiceExtensionAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class ServiceExtAbility extends ServiceExtensionAbility { onRequest(want: Want, startId: number) { console.info('onRequest'); let windowClass: window.Window | undefined = undefined; let config: window.Configuration = { name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; try { window.createWindow(config, (err: BusinessError, data) => { let errCode: number = err.code; if (errCode) { console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; }); let requestInfo = dialogRequest.getRequestInfo(want) windowClass.bindDialogTarget(requestInfo, () => { console.info('Dialog Window Need Destroy.'); }, (err: BusinessError) => { let errCode: number = err.code; if (errCode) { console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in binding dialog target.'); }); } catch (err) { console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`) } } } ``` ### bindDialogTarget9+ bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>): Promise<void> 绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | -------------------- | | requestInfo | [dialogRequest.RequestInfo](../apis-ability-kit/js-apis-app-ability-dialogRequest.md#requestinfo) | 是 | 目标窗口RequestInfo值。 | | deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { dialogRequest, Want, ServiceExtensionAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class ServiceExtAbility extends ServiceExtensionAbility { onRequest(want: Want, startId: number) { console.info('onRequest'); let windowClass: window.Window | undefined = undefined; let config: window.Configuration = { name: "test", windowType: window.WindowType.TYPE_DIALOG, ctx: this.context }; try { window.createWindow(config, (err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to create the window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; }); let requestInfo = dialogRequest.getRequestInfo(want) let promise = windowClass.bindDialogTarget(requestInfo, () => { console.info('Dialog Window Need Destroy.'); }); promise.then(() => { console.info('Succeeded in binding dialog target.'); }).catch((err: BusinessError) => { console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`); }); } catch (err) { console.error(`Failed to bind dialog target. Cause code: ${err.code}, message: ${err.message}`) } } } ``` ### setWakeUpScreen9+ setWakeUpScreen(wakeUp: boolean): void 窗口唤醒屏幕。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------------- | ------- | ---- | ---------------------------- | | wakeUp | boolean | 是 | 是否设置唤醒屏幕。true表示唤醒;false表示不唤醒。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts let wakeUp: boolean = true; try { windowClass.setWakeUpScreen(wakeUp); } catch (exception) { console.error(`Failed to wake up the screen. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setSnapshotSkip9+ setSnapshotSkip(isSkip: boolean): void 截屏录屏是否忽略当前窗口。此接口一般用于禁止截屏/录屏的场景。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------- | ------- | ---- | -------------------- | | isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。
true表示忽略当前窗口,false表示不忽略当前窗口。
| **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | ```ts let isSkip: boolean = true; try { windowClass.setSnapshotSkip(isSkip); } catch (exception) { console.error(`Failed to Skip. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setForbidSplitMove9+ setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void 设置主窗口在分屏模式下是否被禁止移动,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | -------------------- | | isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; windowStage.getMainWindow((err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; let isForbidSplitMove: boolean = true; try { windowClass.setForbidSplitMove(isForbidSplitMove, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to forbid window moving in split screen mode. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in forbidding window moving in split screen mode.'); }); } catch (exception) { console.error(`Failed to forbid window moving in split screen mode. Cause code: ${exception.code}, message: ${exception.message}`); } }); } } ``` ### setForbidSplitMove9+ setForbidSplitMove(isForbidSplitMove: boolean): Promise<void> 设置主窗口在分屏模式下是否被禁止移动,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------- | ---- | -------------------- | | isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; windowStage.getMainWindow((err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } windowClass = data; let isForbidSplitMove: boolean = true; try { let promise = windowClass.setForbidSplitMove(isForbidSplitMove); promise.then(() => { console.info('Succeeded in forbidding window moving in split screen mode.'); }).catch((err: BusinessError) => { console.error(`Failed to forbid window moving in split screen mode. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to forbid window moving in split screen mode. Cause code: ${exception.code}, message: ${exception.message}`); } }); } } ``` ### opacity9+ opacity(opacity: number): void 设置窗口不透明度。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- |----------------------------------------------------| | opacity | number | 是 | 不透明度。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示完全透明,1.0表示完全不透明。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts try { windowClass.opacity(0.5); } catch (exception) { console.error(`Failed to opacity. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### scale9+ scale(scaleOptions: ScaleOptions): void 设置窗口缩放参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ------------------------------ | ---- | ---------- | | scaleOptions | [ScaleOptions](#scaleoptions9) | 是 | 缩放参数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts let obj: window.ScaleOptions = { x: 2.0, y: 1.0, pivotX: 0.5, pivotY: 0.5 }; try { windowClass.scale(obj); } catch (exception) { console.error(`Failed to scale. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### rotate9+ rotate(rotateOptions: RotateOptions): void 设置窗口旋转参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------- | -------------------------------- | ---- | ---------- | | rotateOptions | [RotateOptions](#rotateoptions9) | 是 | 旋转参数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts let obj: window.RotateOptions = { x: 1.0, y: 1.0, z: 45.0, pivotX: 0.5, pivotY: 0.5 }; try { windowClass.rotate(obj); } catch (exception) { console.error(`Failed to rotate. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### translate9+ translate(translateOptions: TranslateOptions): void 设置窗口平移参数。仅支持在[自定义系统窗口的显示与隐藏动画](../../windowmanager/system-window-stage.md#自定义系统窗口的显示与隐藏动画)中使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------------- | -------------------------------------- | ---- | -------------------- | | translateOptions | [TranslateOptions](#translateoptions9) | 是 | 平移参数,单位为px。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts let obj: window.TranslateOptions = { x: 100.0, y: 0.0, z: 0.0 }; try { windowClass.translate(obj); } catch (exception) { console.error(`Failed to translate. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### getTransitionController9+ getTransitionController(): TransitionController 获取窗口属性转换控制器。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **返回值:** | 类型 | 说明 | | ---------------------------------------------- | ---------------- | | [TransitionController](#transitioncontroller9) | 属性转换控制器。 | **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts let controller = windowClass.getTransitionController(); // 获取属性转换控制器 ``` ### setBlur9+ setBlur(radius: number): void 设置窗口模糊。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- |--------------------------------------------------| | radius | number | 是 | 表示窗口模糊的半径值。该参数为浮点数,单位为px,取值范围为[0, +∞),取值为0.0时表示关闭窗口模糊。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts try { windowClass.setBlur(4.0); } catch (exception) { console.error(`Failed to set blur. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setBackdropBlur9+ setBackdropBlur(radius: number): void 设置窗口背景模糊。 窗口背景是指窗口覆盖的下层区域,与窗口大小相同。 需要通过[setWindowBackgroundColor](js-apis-window.md#setwindowbackgroundcolor9)将窗口内容背景设置成透明,否则无法看到模糊效果。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- |-------------------------------------------------------| | radius | number | 是 | 表示窗口背景模糊的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0表示关闭窗口背景模糊。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts try { windowClass.setWindowBackgroundColor('#00FFFFFF'); windowClass.setBackdropBlur(4.0); } catch (exception) { console.error(`Failed to set backdrop blur. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setBackdropBlurStyle9+ setBackdropBlurStyle(blurStyle: BlurStyle): void 设置窗口背景模糊类型。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | --------- | ---- | ---------------------- | | blurStyle | [BlurStyle](#blurstyle9) | 是 | 表示窗口背景模糊类型。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts try { windowClass.setBackdropBlurStyle(window.BlurStyle.THIN); } catch (exception) { console.error(`Failed to set backdrop blur style. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setShadow9+ setShadow(radius: number, color?: string, offsetX?: number, offsetY?: number): void 设置窗口边缘阴影。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- |-------------------------------------------------------------| | radius | number | 是 | 表示窗口边缘阴影的模糊半径。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示关闭窗口边缘阴影。 | | color | string | 否 | 表示窗口边缘阴影的颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00`或`#FF00FF00`。 | | offsetX | number | 否 | 表示窗口边缘阴影的X轴的偏移量。该参数为浮点数,单位为px。 | | offsetY | number | 否 | 表示窗口边缘阴影的Y轴的偏移量。该参数为浮点数,单位为px。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts try { windowClass.setShadow(4.0, '#FF00FF00', 2, 3); } catch (exception) { console.error(`Failed to set shadow. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setCornerRadius9+ setCornerRadius(cornerRadius: number): void 设置窗口圆角半径。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------- | ---- |----------------------------------------------------| | cornerRadius | number | 是 | 表示窗口圆角的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts try { windowClass.setCornerRadius(4.0); } catch (exception) { console.error(`Failed to set corner radius. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setTouchableAreas12+ setTouchableAreas(rects: Array<Rect>): void 实现设置窗口可触摸区域;不设置时默认整个窗口区域可触摸;设置窗口可触摸区域后,区域外触摸事件将被透传;如果窗口区域发生变化需要重新设置。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | rects | Array<[Rect](js-apis-window.md#rect7)> | 是 | 窗口可触摸区域。可触摸区域最大个数不能超过10个,且范围不能超出窗口区域。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | **示例:** ```ts try { windowClass.setTouchableAreas([{left: 100, top: 100, width: 200, height:200}, {left: 400, top: 100, width: 200, height:200}]); } catch (exception) { console.error(`Failed to set touchable areas. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### raiseToAppTop10+ raiseToAppTop(callback: AsyncCallback<void>): void 提升应用子窗口到应用顶层。使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | | 1300009 | The parent window is invalid. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; windowClass.raiseToAppTop((err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to raise the window to app top. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in raising the window to app top.'); }); ``` ### setWaterMarkFlag10+ setWaterMarkFlag(enable: boolean): Promise<void> 为当前窗口添加或删除安全水印标志,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------- | --- | ------------------------------------------------ | | enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ---------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300008 | The display device is abnormal. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let enable = true; let promise = windowClass.setWaterMarkFlag(enable); promise.then(() => { console.info('Succeeded in setting water mark flag of window.'); }).catch((err: BusinessError) => { console.error(`Failed to set water mark flag of window. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to set water mark flag of window. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setWaterMarkFlag10+ setWaterMarkFlag(enable: boolean, callback: AsyncCallback<void>): void 为当前窗口添加或删除安全水印标志,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | --- | ----------------------------------------------- | | enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ---------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300008 | The display device is abnormal. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let enable: boolean = true; windowClass.setWaterMarkFlag(enable, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to set water mark flag of window. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in setting water mark flag of window.'); }); } catch (exception) { console.error(`Failed to set water mark flag of window. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### setHandwritingFlag12+ setHandwritingFlag(enable: boolean): Promise<void> 为当前窗口添加或移除手写标志,添加该标志后窗口只响应手写笔事件,不响应触屏事件。使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------- | --- | ------------------------------------------------ | | enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示移除。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { let enable = true; let promise = windowClass.setHandwritingFlag(enable); promise.then(() => { console.info('Succeeded in setting handwriting flag of window.'); }).catch((err: BusinessError) => { console.error(`Failed to set handwriting flag of window. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to set handwriting flag of window. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### raiseAboveTarget10+ raiseAboveTarget(windowId: number, callback: AsyncCallback<void>): void 将同一个主窗口下的子窗口提升到目标子窗口之上。使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | windowId | number | 是 | 目标子窗口的id,通过[getWindowProperties](js-apis-window.md#getwindowproperties9)接口获取到[properties](js-apis-window.md#windowproperties)后,再通过properties.id获取 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ---------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: Mandatory parameters are left unspecified. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | | 1300009 | The parent window is invalid. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; // 创建子窗 try { let subWindow = windowStage.createSubWindow("testSubWindow"); subWindow.then((data) => { if (data == null) { console.error("Failed to create the subWindow. Cause: The data is empty"); return; } windowClass = data; // windowClass的获取需放在targetWindow之上 let targetWindow: window.Window = windowClass; let properties = targetWindow.getWindowProperties(); let targetId = properties.id; windowClass.raiseAboveTarget(targetId, (err) => { if (err.code) { console.error(`Failed to raise the subWindow to target subWindow top. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in raising the subWindow to target subWindow top.'); }); }); } catch (exception) { console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); } } } ``` ### raiseAboveTarget10+ raiseAboveTarget(windowId: number): Promise<void> 将同一个主窗下的子窗口提升到目标子窗口之上。使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | windowId | number | 是 | 目标子窗口的id,通过[getWindowProperties](js-apis-window.md#getwindowproperties9)接口获取到[properties](js-apis-window.md#windowproperties)后,再通过properties.id获取 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: Mandatory parameters are left unspecified. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | | 1300009 | The parent window is invalid. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; // 创建子窗 try { let subWindow = windowStage.createSubWindow("testSubWindow"); subWindow.then((data) => { if (data == null) { console.error("Failed to create the subWindow. Cause: The data is empty"); return; } windowClass = data; // windowClass的获取需放在targetWindow之上 let targetWindow: window.Window = windowClass; let properties = targetWindow.getWindowProperties(); let targetId = properties.id; let promise = windowClass.raiseAboveTarget(targetId); promise.then(()=> { console.info('Succeeded in raising the subWindow to target subWindow top.'); }).catch((err: BusinessError)=>{ console.error(`Failed to raise the subWindow to target subWindow top. Cause code: ${err.code}, message: ${err.message}`); }); }); } catch (exception) { console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); } } } ``` ### setRaiseByClickEnabled10+ setRaiseByClickEnabled(enable: boolean, callback: AsyncCallback<void>): void 禁止/使能子窗口点击抬升功能。使用callback异步回调。 通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | | 1300009 | The parent window is invalid. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { console.info('onWindowStageCreate'); let windowClass: window.Window | undefined = undefined; // 创建子窗 try { let subWindow = windowStage.createSubWindow("testSubWindow"); subWindow.then((data) => { if (data == null) { console.error("Failed to create the subWindow. Cause: The data is empty"); return; } windowClass = data; let enabled = false; windowClass.setRaiseByClickEnabled(enabled, (err) => { if (err.code) { console.error(`Failed to disable the raise-by-click function. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in disabling the raise-by-click function.'); }); }); } catch (exception) { console.error(`Failed to create the subWindow. Cause code: ${exception.code}, message: ${exception.message}`); } } } ``` ### enableDrag14+ enableDrag(enable: boolean): Promise<void> 使能/禁止拖拽窗口。使用Promise异步回调。 使能后,将允许通过鼠标对窗口进行拉伸操作。 仅对2in1设备的系统窗口生效,其它设备类型调用此接口会报错。 **系统能力:** SystemCapability.Window.SessionManager **系统接口:** 此接口为系统接口。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------- | -- | --------- | | enable| boolean | 是 | 是否允许拖拽。
true表示允许,false表示不允许。
| **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | -------- | -------------------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { windowClass.enableDrag(true).then(() => { console.info('succeeded in setting window draggable'); }).catch((err: BusinessError) => { console.error(`Failed to set window draggable. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { console.error(`Failed to set window draggable. Cause code: ${exception.code}, message: ${exception.message}`); } ``` ### hideNonSystemFloatingWindows11+ hideNonSystemFloatingWindows(shouldHide: boolean, callback: AsyncCallback<void>): void 设置是否隐藏非系统级悬浮窗口。使用callback异步回调。 非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | ---------- | | shouldHide | boolean | 是 | 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts // EntryAbility.ets import { UIAbility, Want } from '@kit.AbilityKit'; export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage) { // 加载主窗口对应的页面 windowStage.loadContent('pages/Index', (err) => { if (err.code) { console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in loading the content.'); }); // 获取应用主窗口。 let mainWindow: window.Window | undefined = undefined; windowStage.getMainWindow((err, data) => { if (err.code) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } mainWindow = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); let shouldHide = true; // 调用带callback参数的hideNonSystemFloatingWindows接口 mainWindow.hideNonSystemFloatingWindows(shouldHide, (err) => { if (err.code) { console.error(`Failed to hide the non-system floating windows. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in hiding the non-system floating windows.'); }); }); } } ``` ### hideNonSystemFloatingWindows11+ hideNonSystemFloatingWindows(shouldHide: boolean): Promise<void> 设置是否隐藏非系统级悬浮窗口。使用callback异步回调。 非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------------------------- | ---- | ---------- | | shouldHide | boolean | 是 | 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts // EntryAbility.ets import { UIAbility, Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage) { // 加载主窗口对应的页面 windowStage.loadContent('pages/Index', (err) => { if (err.code) { console.error(`Failed to load the content. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in loading the content.'); }); // 获取应用主窗口。 let mainWindow: window.Window | undefined = undefined; windowStage.getMainWindow((err, data) => { if (err.code) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } mainWindow = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); let shouldHide = true; // 调用hideNonSystemFloatingWindows接口,获取promise对象 let promise = mainWindow.hideNonSystemFloatingWindows(shouldHide); promise.then(()=> { console.info('Succeeded in hiding the non-system floating windows.'); }).catch((err: BusinessError)=>{ console.error(`Failed to hide the non-system floating windows. Cause code: ${err.code}, message: ${err.message}`); }); }); } } ``` ### setTopmost12+ setTopmost(isTopmost: boolean): Promise<void> 系统应用主窗口调用,实现将窗口置于所有应用窗口之上不被遮挡,使用Promise异步回调。 仅对2in1设备的悬浮窗口生效。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | isTopmost | boolean | 是 | 是否将系统应用主窗口置顶,true表示置顶,false表示取消置顶。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | | 1300004 | Unauthorized operation. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage): void { // ... windowStage.getMainWindow().then((window) => { let isTopmost: boolean = true; let promise = window.setTopmost(isTopmost); promise.then(() => { console.info('Succeeded in setting the main window to be topmost.'); }).catch((err: BusinessError) => { console.error(`Failed to set the main window to be topmost. Cause code: ${err.code}, message: ${err.message}`); }); }); } } ``` ### setSingleFrameComposerEnabled11+ setSingleFrameComposerEnabled(enable: boolean): Promise<void> 禁止/使能单帧合成渲染节点的功能。使用Promise异步回调。 单帧合成渲染节点的功能主要用于跟手性要求较高的场景,使能该功能之后可以降低渲染节点的上屏延时。通过setSingleFrameComposerEnabled接口,如果enable设置为true,则使能单帧合成渲染节点的功能,否则禁止单帧合成渲染节点的功能。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | enable | boolean | 是 | 设置单帧合成渲染节点的功能是否使能,true表示使能,false表示禁止。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let enable = true; let promise = windowClass.setSingleFrameComposerEnabled(enable); promise.then(()=> { console.info('Succeeded in enabling the single-frame-composer function.'); }).catch((err: BusinessError)=>{ console.error(`Failed to enable the single-frame-composer function. code:${err.code}, message:${err.message}.`); }); ``` ### setTitleButtonVisible12+ setTitleButtonVisible(isMaximizeVisible: boolean, isMinimizeVisible: boolean, isSplitVisible: boolean): void 设置主窗标题栏上的最大化、最小化、分屏按钮是否可见。 此接口仅支持2in1设备且仅对在当前场景下可见的标题栏按钮(最大化、最小化、分屏)生效。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------- | ---- | --------------------------------------------- | | isMaximizeVisible | boolean | 是 | 设置最大化按钮是否可见,true为可见,false为隐藏。 | | isMinimizeVisible | boolean | 是 | 设置最小化按钮是否可见,true为可见,false为隐藏。 | | isSplitVisible | boolean | 是 | 设置分屏按钮是否可见,true为可见,false为隐藏。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300004 | Unauthorized operation. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { // 加载主窗口对应的页面 windowStage.loadContent('pages/Index', (err) => { let mainWindow: window.Window | undefined = undefined; // 获取应用主窗口。 windowStage.getMainWindow().then( data => { mainWindow = data; console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); // 调用setTitleButtonVisible接口,隐藏主窗标题栏最大化、最小化、分屏按钮。 mainWindow.setTitleButtonVisible(false, false, false); } ).catch((err: BusinessError) => { if(err.code){ console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); } }); }); } } ``` ### setWindowType(deprecated) setWindowType(type: WindowType, callback: AsyncCallback<void>): void 设置窗口类型,使用callback异步回调。 **系统接口:** 此接口为系统接口。 > **说明:** > > 从 API version 7开始支持,从API version 9开始废弃。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | type | [WindowType](#windowtype7) | 是 | 窗口类型。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let type = window.WindowType.TYPE_SYSTEM_ALERT; windowClass.setWindowType(type, (err: BusinessError) => { const errCode: number = err.code; if (errCode) { console.error(`Failed to set the window type. Cause code: ${err.code}, message: ${err.message}`); return; } console.info('Succeeded in setting the window type.'); }); ``` ### setWindowType(deprecated) setWindowType(type: WindowType): Promise<void> 设置窗口类型,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 > **说明:** > > 从 API version 7开始支持,从API version 9开始废弃。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------------------------- | ---- | ---------- | | type | [WindowType](#windowtype7) | 是 | 窗口类型。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let type = window.WindowType.TYPE_SYSTEM_ALERT; let promise = windowClass.setWindowType(type); promise.then(() => { console.info('Succeeded in setting the window type.'); }).catch((err: BusinessError) => { console.error(`Failed to set the window type. Cause code: ${err.code}, message: ${err.message}`); }); ``` ### requestFocus13+ requestFocus(isFocused: boolean): Promise<void> 支持当前窗口主动请求获焦/失焦,使用Promise异步回调。调用成功即返回,该接口返回值不代表最终获焦/失焦生效结果。可使用[on('windowEvent')](js-apis-window.md#onwindowevent10)监听窗口获焦/失焦状态。 获焦请求发送后,窗口获焦结果受到窗口可获焦属性及窗口可见状态的限制。获焦成功的窗口需满足以下约束:1.窗口支持获焦;2.窗口可见(窗口已显示,未销毁且未退至后台)。 失焦请求发送后,窗口无条件失焦。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | isFocused | boolean | 是 | 是否获取焦点,true表示请求获焦,false表示请求失焦。 | **返回值:** | 类型 | 说明 | | ------------------- | ------------------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported. Failed to call the API due to limited device capabilities. | | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let isFocused: boolean = true; let promise = windowClass.requestFocus(isFocused); promise.then(() => { console.info('Succeeded in requesting focus.'); }).catch((err: BusinessError) => { console.error(`Failed to request focus. Cause code: ${err.code}, message: ${err.message}`); }); ``` ## SubWindowOptions11+ 子窗口创建参数。 **系统能力:** SystemCapability.Window.SessionManager | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------- | ---- | ---- | ---- | ----------- | | isTopmost12+ | boolean | 否 | 是 | 子窗口是否启用置顶属性。true表示子窗口置顶,false表示子窗口不置顶。不设置,则默认为false。 | ## WindowStage9+ 窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。 下列API示例中都需在[onWindowStageCreate()](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 ### disableWindowDecor9+ disableWindowDecor(): void 禁止窗口装饰。 禁止窗口装饰后,当主窗口进入全屏沉浸状态时,此时鼠标Hover到上方窗口标题栏热区上会显示悬浮标题栏。若想禁用悬浮标题栏显示,请使用[setTitleAndDockHoverShown()](./js-apis-window.md#settitleanddockhovershown14)接口。 **模型约束:** 此接口仅可在Stage模型下使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **错误码:** 以下错误码的详细介绍请参见[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 1300002 | This window state is abnormal. | | 1300005 | This window stage is abnormal. | **示例:** ```ts // EntryAbility.ets import { UIAbility, Want } from '@kit.AbilityKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage) { console.log('disableWindowDecor'); windowStage.disableWindowDecor(); } }; ``` ### setShowOnLockScreen9+ setShowOnLockScreen(showOnLockScreen: boolean): void 设置应用显示在锁屏之上。 **系统接口:** 此接口为系统接口。 **模型约束:** 此接口仅可在Stage模型下使用。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------------- | ------- | ---- | ---------------------------- | | showOnLockScreen | boolean | 是 | 是否设置应用显示在锁屏之上。true表示显示在锁屏之上;false表示不显示在锁屏之上。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[窗口错误码](errorcode-window.md)。 | 错误码ID | 错误信息 | | ------- | ------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 1300002 | This window state is abnormal. | | 1300005 | This window stage is abnormal. | **示例:** ```ts // EntryAbility.ets import { UIAbility } from '@kit.AbilityKit'; export default class EntryAbility extends UIAbility { // ... onWindowStageCreate(windowStage: window.WindowStage) { console.log('onWindowStageCreate'); try { windowStage.setShowOnLockScreen(true); } catch (exception) { console.error(`Failed to show on lockscreen. Cause code: ${exception.code}, message: ${exception.message}`); } } }; ``` ## TransitionContext9+ 属性转换的上下文信息。 **系统接口:** 此接口为系统接口。 ### 属性 **系统接口:** 此接口为系统接口。 **系统能力**:SystemCapability.WindowManager.WindowManager.Core | 名称 | 类型 | 可读 | 可写 | 说明 | | --------------------- | ----------------- | ---- | ---- | ---------------- | | toWindow9+ | [Window](#window) | 是 | 是 | 动画的目标窗口。 | ### completeTransition9+ completeTransition(isCompleted: boolean): void 设置属性转换的最终完成状态。该函数需要在动画函数[animateTo()](arkui-ts/ts-explicit-animation.md)执行后设置。 **系统接口:** 此接口为系统接口。 **系统能力**:SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------- | ---- | ------------------------------------------------------------ | | isCompleted | boolean | 是 | 窗口属性转换是否完成。true表示完成本次转换;false表示撤销本次转换。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | **示例:** ```ts (context: window.TransitionContext) => { let toWindow: window.Window = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 curve: Curve.EaseInOut, // 动画曲线 delay: 0, // 动画延迟 iterations: 1, // 播放次数 playMode: PlayMode.Normal, // 动画模式 }, () => { let obj: window.TranslateOptions = { x: 100.0, y: 0.0, z: 0.0 }; toWindow.translate(obj); console.info('toWindow translate end'); } ); try { context.completeTransition(true) } catch (exception) { console.error(`toWindow translate fail. Cause code: ${exception.code}, message: ${exception.message}`); } console.info('complete transition end'); }; ``` ## TransitionController9+ 属性转换控制器。使用其子接口之前得先创建系统窗口,参照示例代码。 **系统接口:** 此接口为系统接口。 **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let windowClass: window.Window | undefined = undefined; let config: window.Configuration = { name: "systemTypeWindow", windowType: window.WindowType.TYPE_PANEL, //根据需要自选系统窗口类型 ctx: this.context }; let promise = window.createWindow(config); promise.then((data) => { windowClass = data; console.info('Succeeded in creating the window. Data:' + JSON.stringify(data)); }).catch((err: BusinessError) => { console.error(`Failed to create the Window. Cause code: ${err.code}, message: ${err.message}`); }); ``` ### animationForShown9+ animationForShown(context: TransitionContext): void 窗口显示时的自定义动画配置。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ---------------------------------------- | ---- | -------------------- | | context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | **示例:** ```ts // xxx.ts export class AnimationConfig { private animationForShownCallFunc_: Function = undefined; ShowWindowWithCustomAnimation(windowClass: window.Window, callback) { if (!windowClass) { console.error('windowClass is undefined'); return false; } this.animationForShownCallFunc_ = callback; let controller: window.TransitionController = windowClass.getTransitionController(); controller.animationForShown = (context : window.TransitionContext)=> { this.animationForShownCallFunc_(context); }; windowClass.showWithAnimation(()=>{ console.info('Show with animation success'); }); } } ``` ```ts // xxx.ets let animationConfig = new AnimationConfig(); let systemTypeWindow = window.findWindow("systemTypeWindow"); // 此处需要获取一个系统类型窗口。 try { animationConfig?.ShowWindowWithCustomAnimation(systemTypeWindow, (context : window.TransitionContext)=>{ console.info('complete transition end'); let toWindow = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 curve: Curve.EaseInOut, // 动画曲线 delay: 0, // 动画延迟 iterations: 1, // 播放次数 playMode: PlayMode.Normal, // 动画模式 onFinish: () => { console.info('onFinish in animation'); context.completeTransition(true) } }, () => { let obj : window.TranslateOptions = { x : 100.0, y : 0.0, z : 0.0 }; toWindow.translate(obj); // 设置动画过程中的属性转换 console.info('toWindow translate end in animation'); }); console.info('complete transition end'); }); } catch (error) { console.error(`ShowWindowWithCustomAnimation error code: ${error.code}, message: ${error.message}`); } ``` ### animationForHidden9+ animationForHidden(context: TransitionContext): void 窗口隐藏时的自定义动画配置。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.WindowManager.WindowManager.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ---------------------------------------- | ---- | -------------------- | | context | [TransitionContext](#transitioncontext9) | 是 | 属性转换时的上下文。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ------- | -------------------------------- | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | **示例:** ```ts // xxx.ts export class AnimationConfig { private animationForHiddenCallFunc_: Function = undefined; HideWindowWithCustomAnimation(windowClass: window.Window, callback) { if (!windowClass) { console.error('windowClass is undefined'); return false; } this.animationForHiddenCallFunc_ = callback; let controller: window.TransitionController = windowClass.getTransitionController(); controller.animationForHidden = (context : window.TransitionContext)=> { this.animationForHiddenCallFunc_(context); }; windowClass.hideWithAnimation(()=>{ console.info('hide with animation success'); }); } } ``` ```ts // xxx.ets let animationConfig = new AnimationConfig(); let systemTypeWindow = window.findWindow("systemTypeWindow"); // 此处需要获取一个系统类型窗口。 try { animationConfig?.HideWindowWithCustomAnimation(systemTypeWindow, (context : window.TransitionContext)=>{ console.info('complete transition end'); let toWindow = context.toWindow; animateTo({ duration: 1000, // 动画时长 tempo: 0.5, // 播放速率 curve: Curve.EaseInOut, // 动画曲线 delay: 0, // 动画延迟 iterations: 1, // 播放次数 playMode: PlayMode.Normal, // 动画模式 onFinish: () => { console.info('onFinish in animation'); context.completeTransition(true) } }, () => { let obj : window.TranslateOptions = { x : 100.0, y : 0.0, z : 0.0 }; toWindow.translate(obj); // 设置动画过程中的属性转换 console.info('toWindow translate end in animation'); }); console.info('complete transition end'); }); } catch (error) { console.error(`HideWindowWithCustomAnimation error code: ${error.code}, message: ${error.message}` ); } ``` ## ExtensionWindowAttribute14+ 扩展窗口的属性枚举。 **模型约束:** 此接口仅可在Stage模型下使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager | 名称 | 值 | 说明 | | ---------- | ----- | ----------- | | SYSTEM_WINDOW | 0 | 系统窗口。| | SUB_WINDOW | 1 | 子窗口。| ## SystemWindowOptions14+ 系统窗口的创建参数。 **模型约束:** 此接口仅可在Stage模型下使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager | 名称 | 类型 | 只读 |可选 | 说明 | | ------ | ------------------------- | ---- | ---- |---------- | | windowType | [WindowType](#windowtype7) | 否 | 否 | 窗口类型。无默认类型,不配置会导致窗口创建失败。不支持TYPE_DIALOG类型。 | ## ExtensionWindowConfig14+ 创建扩展窗口时需要配置的参数。 **模型约束:** 此接口仅可在Stage模型下使用。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.Window.SessionManager | 名称 | 类型 | 只读 |可选 | 说明 | | ------ | ------------------------- | ---- | ---- |---------- | | windowName | string | 否 | 否 | 窗口名。 | | windowAttribute | [ExtensionWindowAttribute](#extensionwindowattribute14) | 否 | 否 | 窗口的属性。用于配置创建的窗口是子窗口还是系统窗口。当windowAttribute配置为SUB_WINDOW时须配置subWindowOptions,当windowAttribute配置为SYSTEM_WINDOW时须配置systemWindowOptions,否则创建窗口失败。| | windowRect | [Rect](js-apis-window.md#rect7) | 否 | 否 | 窗口矩形区域。 | | subWindowOptions | [SubWindowOptions](js-apis-window.md#subwindowoptions11) | 否 | 是 | 创建子窗口的参数。无默认参数,当windowAttribute配置为SUB_WINDOW时必选,否则会导致窗口创建失败。 | | systemWindowOptions | [SystemWindowOptions](#systemwindowoptions14) | 否 | 是 | 创建系统窗口的参数。无默认参数,当windowAttribute配置为SYSTEM_WINDOW时必选,否则会导致窗口创建失败。 |