@ohos.window (窗口)(系统接口)
窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。
该模块提供以下窗口相关的常用功能:
- Window:当前窗口实例,窗口管理器管理的基本单元。
- WindowStage:窗口管理器。管理各个基本窗口单元。
说明:
本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
当前页面仅包含本模块的系统接口,其他公开接口参见@ohos.window (窗口)。
导入模块
import window from '@ohos.window';
WindowType7+
窗口类型枚举。
系统能力: SystemCapability.WindowManager.WindowManager.Core
名称 | 值 | 说明 |
---|---|---|
TYPE_INPUT_METHOD9+ | 2 | 表示输入法窗口。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_STATUS_BAR9+ | 3 | 表示状态栏窗口。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_PANEL9+ | 4 | 表示通知栏。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_KEYGUARD9+ | 5 | 表示锁屏。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_VOLUME_OVERLAY9+ | 6 | 表示音量条。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_NAVIGATION_BAR9+ | 7 | 表示导航栏窗口。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_WALLPAPER9+ | 9 | 表示壁纸。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_DESKTOP9+ | 10 | 表示桌面。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_LAUNCHER_RECENT9+ | 11 | 表示多任务中心。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_LAUNCHER_DOCK9+ | 12 | 表示桌面Dock栏。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_VOICE_INTERACTION9+ | 13 | 表示智慧语音。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_POINTER9+ | 14 | 表示鼠标。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_FLOAT_CAMERA9+ | 15 | 表示相机类型悬浮窗。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_SCREENSHOT9+ | 17 | 表示截屏窗口。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_SYSTEM_TOAST11+ | 18 | 表示顶层提示窗口。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_DIVIDER11+ | 19 | 表示分屏条。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
TYPE_GLOBAL_SEARCH11+ | 20 | 表示全局搜索窗口。 模型约束: 此接口仅可在Stage模型下使用。 系统接口: 此接口为系统接口。 |
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 | 是 | 否 | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 |
isEnable | boolean | 是 | 否 | 当前系统栏是否显示。true表示显示;false表示不显示。 |
region | Rect | 是 | 否 | 当前系统栏的位置及大小。 |
backgroundColor | string | 是 | 否 | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如#00FF00 或#FF00FF00 。 |
contentColor | string | 是 | 否 | 系统栏文字颜色。 |
SystemBarTintState8+
当前系统栏回调信息集合。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
名称 | 类型 | 可读 | 可写 | 说明 |
---|---|---|---|---|
displayId | number | 是 | 否 | 当前物理屏幕id,该参数应为整数。 |
regionTint | Array<SystemBarRegionTint> | 是 | 否 | 当前已改变的所有系统栏信息。 |
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。 |
window.minimizeAll9+
minimizeAll(id: number, callback: AsyncCallback<void>): void
最小化某显示设备下的所有窗口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
id | number | 是 | 显示设备Display的ID号,该参数仅支持整数输入。 |
callback | AsyncCallback<void> | 是 | 回调信息。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import display from '@ohos.display'
import { BusinessError } from '@ohos.base';
let displayClass: display.Display | null = null;
try {
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: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in minimizing all windows.');
});
} catch (exception) {
console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception));
}
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
window.minimizeAll9+
minimizeAll(id: number): Promise<void>
最小化某显示设备下的所有窗口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
id | number | 是 | 显示设备Display的ID号,该参数仅支持整数输入。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import display from '@ohos.display'
import { BusinessError } from '@ohos.base';
let displayClass: display.Display | null = null;
try {
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: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to minimize all windows. Cause: ' + JSON.stringify(exception));
}
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
window.toggleShownStateForAllAppWindows9+
toggleShownStateForAllAppWindows(callback: AsyncCallback<void>): void
多窗口快速切换时隐藏或者恢复应用窗口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调信息。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
window.toggleShownStateForAllAppWindows((err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to toggle shown state for all app windows. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in toggling shown state for all app windows.');
});
window.toggleShownStateForAllAppWindows9+
toggleShownStateForAllAppWindows(): Promise<void>
多窗口快速切换时隐藏或者恢复应用窗口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
window.setWindowLayoutMode9+
setWindowLayoutMode(mode: WindowLayoutMode, callback: AsyncCallback<void>): void
设置窗口布局模式。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | WindowLayoutMode | 是 | 设置的窗口布局模式。 |
callback | AsyncCallback<void> | 是 | 回调信息。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting window layout mode.');
});
} catch (exception) {
console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception));
}
window.setWindowLayoutMode9+
setWindowLayoutMode(mode: WindowLayoutMode): Promise<void>
设置窗口布局模式。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | WindowLayoutMode | 是 | 设置的窗口布局模式。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set window layout mode. Cause: ' + JSON.stringify(exception));
}
window.on('systemBarTintChange')8+
on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void
开启状态栏、导航栏属性变化的监听。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 |
callback | Callback<SystemBarTintState> | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 |
示例:
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: ' + JSON.stringify(exception));
}
window.off('systemBarTintChange')8+
off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState >): void
关闭状态栏、导航栏属性变化的监听。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 |
callback | Callback<SystemBarTintState> | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有状态栏、导航栏属性变化的监听。 |
示例:
try {
window.off('systemBarTintChange');
} catch (exception) {
console.error('Failed to disable the listener for systemBarTint changes. Cause: ' + JSON.stringify(exception));
}
window.on('gestureNavigationEnabledChange')10+
on(type: 'gestureNavigationEnabledChange', callback: Callback<boolean>): void
添加手势导航启用状态变化的监听。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 |
callback | Callback<boolean> | 是 | 回调函数。返回当前手势导航的启用状态。true表示手势导航状态变化为启用;false表示手势导航状态变化为禁用。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
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: ' + JSON.stringify(exception));
}
window.off('gestureNavigationEnabledChange')10+
off(type: 'gestureNavigationEnabledChange', callback?: Callback<boolean>): void
移除手势导航启用状态变化的监听。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'gestureNavigationEnabledChange',即手势导航启用状态变化事件。 |
callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有手势导航启用状态变化的监听。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
try {
window.off('gestureNavigationEnabledChange');
} catch (exception) {
console.error('Failed to disable the listener for gesture navigation status changes. Cause: ' + JSON.stringify(exception));
}
window.on('waterMarkFlagChange')10+
on(type: 'waterMarkFlagChange', callback: Callback<boolean>): void
添加水印启用状态变化的监听。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 |
callback | Callback<boolean> | 是 | 回调函数。返回当前水印的启用状态。true表示当前已启用水印;false表示当前未启用水印。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
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: ' + JSON.stringify(exception));
}
window.off('waterMarkFlagChange')10+
off(type: 'waterMarkFlagChange', callback?: Callback<boolean>): void
移除水印启用状态变化的监听。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | string | 是 | 监听事件,固定为'waterMarkFlagChange',即水印启用状态变化事件。 |
callback | Callback<boolean> | 否 | 已注册的回调函数。如果传入参数,则关闭该监听。如果未传入参数,则关闭所有水印启用状态变化的监听。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
try {
window.off('waterMarkFlagChange');
} catch (exception) {
console.error('Failed to disable the listener for watermark flag changes. Cause: ' + JSON.stringify(exception));
}
window.setGestureNavigationEnabled10+
setGestureNavigationEnabled(enable: boolean, callback: AsyncCallback<void>): void
设置手势导航启用状态。使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 |
callback | AsyncCallback<void> | 是 | 回调信息。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
try {
window.setGestureNavigationEnabled(true, (err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting gesture navigation enabled.');
});
} catch (exception) {
console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception));
}
window.setGestureNavigationEnabled10+
setGestureNavigationEnabled(enable: boolean): Promise<void>
设置手势导航启用状态。使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置手势导航启用状态。true表示启用手势导航;false表示禁用手势导航。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set gesture navigation enabled. Cause: ' + JSON.stringify(exception));
}
window.setWaterMarkImage10+
setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean, callback: AsyncCallback<void>): void
设置水印图片显示状态。使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
pixelMap | image.PixelMap | 是 | 水印图片。 |
enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 |
callback | AsyncCallback<void> | 是 | 回调信息。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import image from '@ohos.multimedia.image';
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing watermark image.');
});
} catch (exception) {
console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception));
}
}).catch((err: BusinessError) => {
console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err));
});
window.setWaterMarkImage10+
setWaterMarkImage(pixelMap: image.PixelMap, enable: boolean): Promise<void>
设置水印图片显示状态。使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
pixelMap | image.PixelMap | 是 | 水印图片。 |
enable | boolean | 是 | 设置是否显示水印图片。true显示水印图片;false表示不显示水印图片。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300003 | This window manager service works abnormally. |
示例:
import image from '@ohos.multimedia.image';
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to show watermark image. Cause: ' + JSON.stringify(exception));
}
}).catch((err: BusinessError) => {
console.error('Failed to create PixelMap. Cause: ' + JSON.stringify(err));
});
Window
当前窗口实例,窗口管理器管理的基本单元。
下列API示例中都需先使用getLastWindow()、createWindow()、findWindow()中的任一方法获取到Window实例(windowClass),再通过此实例调用对应方法。
hide7+
hide (callback: AsyncCallback<void>): void
隐藏当前窗口,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
import { BusinessError } from '@ohos.base';
windowClass.hide((err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in hiding the window.');
});
hide7+
hide(): Promise<void>
隐藏当前窗口,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
import { BusinessError } from '@ohos.base';
let promise = windowClass.hide();
promise.then(() => {
console.info('Succeeded in hiding the window.');
}).catch((err: BusinessError) => {
console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
});
hideWithAnimation9+
hideWithAnimation(callback: AsyncCallback<void>): void
隐藏当前窗口,过程中播放动画,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
示例:
import { BusinessError } from '@ohos.base';
windowClass.hideWithAnimation((err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to hide the window with animation. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in hiding the window with animation.');
});
hideWithAnimation9+
hideWithAnimation(): Promise<void>
隐藏当前窗口,过程中播放动画,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
showWithAnimation9+
showWithAnimation(callback: AsyncCallback<void>): void
显示当前窗口,过程中播放动画,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
示例:
import { BusinessError } from '@ohos.base';
windowClass.showWithAnimation((err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to show the window with animation. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing the window with animation.');
});
showWithAnimation9+
showWithAnimation(): Promise<void>
显示当前窗口,过程中播放动画,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
setWindowMode9+
setWindowMode(mode: WindowMode, callback: AsyncCallback<void>): void
设置窗口模式,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | WindowMode | 是 | 窗口模式。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window mode.');
});
} catch (exception) {
console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception));
}
setWindowMode9+
setWindowMode(mode: WindowMode): Promise<void>
设置窗口类型,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
mode | WindowMode | 是 | 窗口模式。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set the window mode. Cause: ' + JSON.stringify(exception));
}
bindDialogTarget9+
bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>, callback: AsyncCallback<void>): void
绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | rpc.RemoteObject | 是 | 目标窗口token值。 |
deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import rpc from '@ohos.rpc';
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
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:' + JSON.stringify(err));
return;
}
console.info('Succeeded in binding dialog target.');
});
} catch (exception) {
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception));
}
bindDialogTarget9+
bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback<void>): Promise<void>
绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | rpc.RemoteObject | 是 | 目标窗口token值。 |
deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import rpc from '@ohos.rpc';
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
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:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(exception));
}
bindDialogTarget9+
bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>, callback: AsyncCallback<void>): void
绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
requestInfo | dialogRequest.RequestInfo | 是 | 目标窗口RequestInfo值。 |
deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import dialogRequest from '@ohos.app.ability.dialogRequest';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
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:' + JSON.stringify(err));
return;
}
console.info('Succeeded in binding dialog target.');
});
} catch (err) {
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
}
}
}
bindDialogTarget9+
bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback<void>): Promise<void>
绑定模态窗口与目标窗口并添加模态窗口销毁监听,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
requestInfo | dialogRequest.RequestInfo | 是 | 目标窗口RequestInfo值。 |
deathCallback | Callback<void> | 是 | 模态窗口销毁监听。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
import dialogRequest from '@ohos.app.ability.dialogRequest';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
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:' + JSON.stringify(err));
});
} catch (err) {
console.error('Failed to bind dialog target. Cause:' + JSON.stringify(err))
}
}
}
setWakeUpScreen()9+
setWakeUpScreen(wakeUp: boolean): void
窗口唤醒屏幕。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
wakeUp | boolean | 是 | 是否设置唤醒屏幕。true表示唤醒;false表示不唤醒。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
let wakeUp: boolean = true;
try {
windowClass.setWakeUpScreen(wakeUp);
} catch (exception) {
console.error('Failed to wake up the screen. Cause: ' + JSON.stringify(exception));
}
setSnapshotSkip9+
setSnapshotSkip(isSkip: boolean): void
截屏录屏是否忽略当前窗口。此接口一般用于禁止截屏/录屏的场景。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
isSkip | boolean | 是 | 截屏录屏是否忽略当前窗口,默认为false。 true表示忽略当前窗口,false表示不忽略当前窗口。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
let isSkip: boolean = true;
try {
windowClass.setSnapshotSkip(isSkip);
} catch (exception) {
console.error('Failed to Skip. Cause: ' + JSON.stringify(exception));
}
setForbidSplitMove9+
setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void
设置窗口在分屏模式下是否被禁止移动,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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:' + JSON.stringify(err));
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:' + JSON.stringify(exception));
}
setForbidSplitMove9+
setForbidSplitMove(isForbidSplitMove: boolean): Promise<void>
设置窗口在分屏模式下是否被禁止移动,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
isForbidSplitMove | boolean | 是 | 窗口在分屏模式下是否被禁止移动。true表示禁止;false表示不禁止。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to forbid window moving in split screen mode. Cause:' + JSON.stringify(exception));
}
opacity9+
opacity(opacity: number): void
设置窗口不透明度。仅支持在自定义系统窗口的显示与隐藏动画中使用。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
opacity | number | 是 | 不透明度。该参数为浮点数,取值范围为[0.0, 1.0]。0.0表示完全透明,1.0表示完全不透明。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
try {
windowClass.opacity(0.5);
} catch (exception) {
console.error('Failed to opacity. Cause: ' + JSON.stringify(exception));
}
scale9+
scale(scaleOptions: ScaleOptions): void
设置窗口缩放参数。仅支持在自定义系统窗口的显示与隐藏动画中使用。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
scaleOptions | ScaleOptions | 是 | 缩放参数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
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: ' + JSON.stringify(exception));
}
rotate9+
rotate(rotateOptions: RotateOptions): void
设置窗口旋转参数。仅支持在自定义系统窗口的显示与隐藏动画中使用。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
rotateOptions | RotateOptions | 是 | 旋转参数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
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: ' + JSON.stringify(exception));
}
translate9+
translate(translateOptions: TranslateOptions): void
设置窗口平移参数。仅支持在自定义系统窗口的显示与隐藏动画中使用。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
translateOptions | TranslateOptions | 是 | 平移参数,单位为px。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
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: ' + JSON.stringify(exception));
}
getTransitionController9+
getTransitionController(): TransitionController
获取窗口属性转换控制器。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
类型 | 说明 |
---|---|
TransitionController | 属性转换控制器。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
let controller = windowClass.getTransitionController(); // 获取属性转换控制器
setBlur9+
setBlur(radius: number): void
设置窗口模糊。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
radius | number | 是 | 表示窗口模糊的半径值。该参数为浮点数,单位为px,取值范围为[0, +∞),取值为0.0时表示关闭窗口模糊。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
try {
windowClass.setBlur(4.0);
} catch (exception) {
console.error('Failed to set blur. Cause: ' + JSON.stringify(exception));
}
setBackdropBlur9+
setBackdropBlur(radius: number): void
设置窗口背景模糊。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
radius | number | 是 | 表示窗口背景模糊的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0表示关闭窗口背景模糊。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
try {
windowClass.setBackdropBlur(4.0);
} catch (exception) {
console.error('Failed to set backdrop blur. Cause: ' + JSON.stringify(exception));
}
setBackdropBlurStyle9+
setBackdropBlurStyle(blurStyle: BlurStyle): void
设置窗口背景模糊类型。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
blurStyle | BlurStyle | 是 | 表示窗口背景模糊类型。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
try {
windowClass.setBackdropBlurStyle(window.BlurStyle.THIN);
} catch (exception) {
console.error('Failed to set backdrop blur style. Cause: ' + JSON.stringify(exception));
}
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。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
try {
windowClass.setShadow(4.0, '#FF00FF00', 2, 3);
} catch (exception) {
console.error('Failed to set shadow. Cause: ' + JSON.stringify(exception));
}
setCornerRadius9+
setCornerRadius(cornerRadius: number): void
设置窗口圆角半径。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
radius | number | 是 | 表示窗口圆角的半径值。该参数为浮点数,单位为px,取值范围为[0.0, +∞),取值为0.0时表示没有窗口圆角。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300004 | Unauthorized operation. |
示例:
try {
windowClass.setCornerRadius(4.0);
} catch (exception) {
console.error('Failed to set corner radius. Cause: ' + JSON.stringify(exception));
}
raiseToAppTop10+
raiseToAppTop(callback: AsyncCallback<void>): void
提升应用子窗口到应用顶层。使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
1300009 | The parent window is invalid. |
示例:
import { BusinessError } from '@ohos.base';
windowClass.raiseToAppTop((err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in raising the window to app top.');
});
raiseToAppTop10+
raiseToAppTop(): Promise<void>
提升应用子窗口到应用顶层。使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
1300009 | The parent window is invalid. |
示例:
import { BusinessError } from '@ohos.base';
let promise = windowClass.raiseToAppTop();
promise.then(() => {
console.info('Succeeded in raising the window to app top.');
}).catch((err: BusinessError) => {
console.error('Failed to raise the window to app top. Cause: ' + JSON.stringify(err));
});
setWaterMarkFlag10+
setWaterMarkFlag(enable: boolean): Promise<void>
为当前窗口添加或删除安全水印标志,使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300008 | The operation is on invalid display. |
示例:
import { BusinessError } from '@ohos.base';
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:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception));
}
setWaterMarkFlag10+
setWaterMarkFlag(enable: boolean, callback: AsyncCallback<void>): void
为当前窗口添加或删除安全水印标志,使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 是否对窗口添加标志位。true表示添加,false表示删除。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300008 | The operation is on invalid display. |
示例:
import { BusinessError } from '@ohos.base';
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:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting water mark flag of window.');
});
} catch (exception) {
console.error('Failed to set water mark flag of window. Cause: ' + JSON.stringify(exception));
}
raiseAboveTarget10+
raiseAboveTarget(windowId: number, callback: AsyncCallback<void>): void
将同一个主窗口下的子窗口提升到目标子窗口之上。使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
windowId | number | 是 | 目标子窗口的id,通过getWindowProperties接口获取到properties后,再通过properties.id获取 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
1300009 | The parent window is invalid. |
示例:
// 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: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in raising the subWindow to target subWindow top.');
});
raiseAboveTarget10+
raiseAboveTarget(windowId: number): Promise<void>
将同一个主窗下的子窗口提升到目标子窗口之上。使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
windowId | number | 是 | 目标子窗口的id,通过getWindowProperties接口获取到properties后,再通过properties.id获取 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
1300009 | The parent window is invalid. |
示例:
// 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)=>{
console.error('Failed to raise the subWindow to target subWindow top. Cause: ' + JSON.stringify(err));
});
setRaiseByClickEnabled10+
setRaiseByClickEnabled(enable: boolean, callback: AsyncCallback<void>): void
禁止/使能子窗口点击抬升功能。使用callback异步回调。
通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
1300009 | The parent window is invalid. |
示例:
let enabled = false;
windowClass.setRaiseByClickEnabled(enabled, (err) => {
if (err.code) {
console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in disabling the raise-by-click function.');
});
setRaiseByClickEnabled10+
setRaiseByClickEnabled(enable: boolean): Promise<void>
禁止/使能子窗点击抬升功能。使用Promise异步回调。
通常来说,点击一个子窗口,会将该子窗口显示到最上方,如果设置为false,那么点击子窗口的时候,不会将该子窗口显示到最上方,而是保持不变。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置子窗口点击抬升功能是否使能,true表示使能,false表示禁止。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
1300009 | The parent window is invalid. |
示例:
let enabled = false;
let promise = windowClass.setRaiseByClickEnabled(enabled);
promise.then(()=> {
console.info('Succeeded in disabling the raise-by-click function.');
}).catch((err)=>{
console.error('Failed to disable the raise-by-click function. Cause: ' + JSON.stringify(err));
});
setResizeByDragEnabled10+
setResizeByDragEnabled(enable: boolean, callback: AsyncCallback<void>): void
禁止/使能通过拖拽方式缩放主窗口的功能。使用callback异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 为主窗口加载对应的目标页面。
windowStage.loadContent("pages/page2", (err) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
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: ' + JSON.stringify(err));
return;
}
mainWindow = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
let enabled = false;
// 调用setResizeByDragEnabled接口。
mainWindow.setResizeByDragEnabled(enabled, (err) => {
if (err.code) {
console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the function of disabling the resize by dragg window.');
});
})
}
};
setResizeByDragEnabled10+
setResizeByDragEnabled(enable: boolean): Promise<void>
禁止/使能通过拖拽方式缩放主窗口的功能。使用Promise异步回调。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置窗口是否使能通过拖拽进行缩放,true表示使能,false表示禁止。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
示例:
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 为主窗口加载对应的目标页面。
windowStage.loadContent("pages/page2", (err) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
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: ' + JSON.stringify(err));
return;
}
mainWindow = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
let enabled = false;
// 获取setResizeByDragEnabled接口的promise对象
let promise = mainWindow.setResizeByDragEnabled(enabled);
promise.then(()=> {
console.info('Succeeded in setting the function of disabling the resize by dragg window.');
}).catch((err)=>{
console.error('Failed to set the function of disabling the resize by dragg window. Cause: ' + JSON.stringify(err));
});
})
}
};
hideNonSystemFloatingWindows11+
hideNonSystemFloatingWindows(shouldHide: boolean, callback: AsyncCallback<void>): void
设置是否隐藏非系统级悬浮窗口。使用callback异步回调。
非系统级悬浮窗口是指非系统应用创建的悬浮窗口。默认情况下,一个系统应用主窗口可以与非系统级悬浮窗口共同显示,即该主窗口可以被上层的非系统级悬浮窗口遮挡,如果设置为true,则所有的非系统级悬浮窗口会被隐藏,此时该主窗口就不会被上层的非系统级悬浮窗口遮挡了。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
shouldHide | boolean | 是 | 指示是否隐藏非系统级的悬浮窗口,true表示隐藏,false表示不隐藏。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
示例:
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
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:' + JSON.stringify(err));
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: ' + JSON.stringify(err));
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: ' + JSON.stringify(err));
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对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300003 | This window manager service works abnormally. |
1300004 | Unauthorized operation. |
示例:
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
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:' + JSON.stringify(err));
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: ' + JSON.stringify(err));
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)=>{
console.error('Failed to hide the non-system floating windows. Cause: ' + JSON.stringify(err));
});
})
}
}
setSingleFrameComposerEnabled11+
setSingleFrameComposerEnabled(enable: boolean): Promise<void>
禁止/使能单帧合成渲染节点的功能。使用Promise异步回调。
单帧合成渲染节点的功能主要用于跟手性要求较高的场景,使能该功能之后可以降低渲染节点的上屏延时。通过setSingleFrameComposerEnabled接口,如果enable设置为true,则使能单帧合成渲染节点的功能,否则禁止单帧合成渲染节点的功能。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Window.SessionManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
enable | boolean | 是 | 设置单帧合成渲染节点的功能是否使能,true表示使能,false表示禁止。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
示例:
import { BusinessError } from '@ohos.base';
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}.');
});
setWindowType(deprecated)
setWindowType(type: WindowType, callback: AsyncCallback<void>): void
设置窗口类型,使用callback异步回调。
系统接口: 此接口为系统接口。
说明:
从 API version 7开始支持,从API version 9开始废弃。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
type | WindowType | 是 | 窗口类型。 |
callback | AsyncCallback<void> | 是 | 回调函数。 |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
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 | 是 | 窗口类型。 |
返回值:
类型 | 说明 |
---|---|
Promise<void> | 无返回结果的Promise对象。 |
示例:
import { BusinessError } from '@ohos.base';
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: ' + JSON.stringify(err));
});
WindowStage9+
窗口管理器。管理各个基本窗口单元,即Window实例。
下列API示例中都需在onWindowStageCreate()函数中使用WindowStage的实例调用对应方法。
disableWindowDecor()9+
disableWindowDecor(): void
禁止窗口装饰。
模型约束: 此接口仅可在Stage模型下使用。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
// ...
onWindowStageCreate(windowStage: window.WindowStage) {
console.log('disableWindowDecor');
windowStage.disableWindowDecor();
}
};
setShowOnLockScreen()9+
setShowOnLockScreen(showOnLockScreen: boolean): void
设置应用显示在锁屏之上。
系统接口: 此接口为系统接口。
模型约束: 此接口仅可在Stage模型下使用。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
showOnLockScreen | boolean | 是 | 是否设置应用显示在锁屏之上。true表示显示在锁屏之上;false表示不显示在锁屏之上。 |
错误码:
以下错误码的详细介绍请参见窗口错误码。
错误码ID | 错误信息 |
---|---|
1300002 | This window state is abnormal. |
1300005 | This window stage is abnormal. |
示例:
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
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:' + JSON.stringify(exception));
}
}
};
TransitionContext9+
属性转换的上下文信息。
系统接口: 此接口为系统接口。
属性
系统接口: 此接口为系统接口。
系统能力:SystemCapability.WindowManager.WindowManager.Core
名称 | 类型 | 可读 | 可写 | 说明 |
---|---|---|---|---|
toWindow9+ | Window | 是 | 是 | 动画的目标窗口。 |
completeTransition9+
completeTransition(isCompleted: boolean): void
设置属性转换的最终完成状态。该函数需要在动画函数animateTo()执行后设置。
系统接口: 此接口为系统接口。
系统能力:SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
isCompleted | boolean | 是 | 窗口属性转换是否完成。true表示完成本次转换;false表示撤销本次转换。 |
示例:
(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.info('toWindow translate fail. Cause: ' + JSON.stringify(exception));
}
console.info('complete transition end');
};
TransitionController9+
属性转换控制器。使用其子接口之前得先创建系统窗口,参照示例代码。
系统接口: 此接口为系统接口。
示例:
import { BusinessError } from '@ohos.base';
let windowClass: window.Window | undefined = undefined;
let config: window.Configuration = {
name: "systemTypeWindow",
windowType: window.WindowType.TYPE_PANEL, //根据需要自选系统窗口类型
ctx: this.context
};
try {
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:' + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to create the window. Cause: ' + JSON.stringify(exception));
}
animationForShown9+
animationForShown(context: TransitionContext): void
窗口显示时的自定义动画配置。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
context | TransitionContext | 是 | 属性转换时的上下文。 |
示例:
// 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');
})
}
}
// 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 err : ' + JSON.stringify(error));
}
animationForHidden9+
animationForHidden(context: TransitionContext): void
窗口隐藏时的自定义动画配置。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.WindowManager.WindowManager.Core
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
context | TransitionContext | 是 | 属性转换时的上下文。 |
示例:
// 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');
})
}
}
// 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 err : ' + JSON.stringify(error));
}