提交 3dedc549 编写于 作者: G ge-yafang

update docs

Signed-off-by: Nge-yafang <geyafang@huawei.com>
上级 0fa1e91e
# 窗口
窗口提供管理窗口的一些基础能力,包括对窗口的创建、销毁,以及对窗口的属性设置等各项功能。
窗口提供管理窗口的一些基础能力,包括对当前窗口的创建、销毁、各属性设置,以及对各窗口间的管理调度。
该模块提供以下窗口相关的常用功能:
- [Window](#window):当前窗口实例,窗口管理器管理的基本单元。
- [WindowStage](#windowstage9):窗口管理器。管理各个基本窗口单元。
> **说明:**
>
......@@ -14,36 +19,36 @@ import window from '@ohos.window';
## WindowType<sup>7+</sup>
窗口类型。
窗口类型枚举
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 默认值 | 说明 |
| 名称 | 值 | 说明 |
| ----------------- | ------ | ------------------ |
| TYPE_APP | 0 | 表示应用子窗口。 |
| TYPE_SYSTEM_ALERT | 1 | 表示系统告警窗口。 |
| TYPE_APP | 0 | 表示应用子窗口。此接口仅可在FA模型下使用。 |
| TYPE_SYSTEM_ALERT | 1 | 表示系统告警窗口。此接口仅可在Stage模型下使用。 |
## AvoidAreaType<sup>7+</sup>
窗口内容需要规避区域的类型。
窗口内容需要规避区域的类型枚举
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 默认值 | 说明 |
| ----------- | ------ | ------------------ |
| 名称 | | 说明 |
| ----------- | ---- | ------------------ |
| TYPE_SYSTEM | 0 | 表示系统默认区域。 |
| TYPE_CUTOUT | 1 | 表示刘海屏区域。 |
## WindowMode<sup>7+</sup>
窗口模式。
窗口模式枚举
此接口为系统接口,三方应用不支持调用。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 默认值 | 说明 |
| ---------- | ------ | ----------------------------- |
| 名称 | | 说明 |
| ---------- | ---- | ----------------------------- |
| UNDEFINED | 1 | 表示APP未定义窗口模式。 |
| FULLSCREEN | 2 | 表示APP全屏模式。 |
| PRIMARY | 3 | 表示APP分屏多窗口主要模式。 |
......@@ -52,16 +57,16 @@ import window from '@ohos.window';
## SystemBarProperties
状态栏导航栏的属性。
状态栏导航栏的属性。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------------------------------------- | -------- | ---- | ---- | ------------------------------------------------------------ |
| statusBarColor | string | 是 | 是 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如"\#00FF00"或"\#FF00FF00"。 |
| statusBarColor | string | 是 | 是 | 状态栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| isStatusBarLightIcon<sup>7+</sup> | boolean | 否 | 是 | 状态栏图标是否为高亮状态。 |
| statusBarContentColor<sup>8+</sup> | string | 否 | 是 | 状态栏文字颜色。 |
| navigationBarColor | string | 是 | 是 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如"\#00FF00"或"\#FF00FF00"。 |
| navigationBarColor | string | 是 | 是 | 导航栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| isNavigationBarLightIcon<sup>7+</sup> | boolean | 否 | 否 | 导航栏图标是否为高亮状态。 |
| navigationBarContentColor<sup>8+</sup> | string | 否 | 是 | 导航栏文字颜色。 |
......@@ -71,14 +76,14 @@ import window from '@ohos.window';
此接口为系统接口,三方应用不支持调用。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| --------------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ |
| type | [WindowType](#windowtype) | 是 | 是 | 当前属性改变的系统栏类型,仅支持类型为导航栏、状态栏的系统栏。 |
| isEnable | boolean | 是 | 是 | 当前系统栏是否显示。 |
| region | [Rect](#rect) | 是 | 是 | 当前系统栏的位置及大小。 |
| backgroundColor | string | 是 | 是 | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如"\#00FF00"或"\#FF00FF00"。 |
| backgroundColor | string | 是 | 是 | 系统栏背景颜色,为十六进制RGB或ARGB颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| contentColor | string | 是 | 是 | 系统栏文字颜色。 |
## SystemBarTintState<sup>8+</sup>
......@@ -87,18 +92,18 @@ import window from '@ohos.window';
此接口为系统接口,三方应用不支持调用。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ---------- | --------------------------------------------------- | ---- | ---- | -------------------------- |
| ---------- | --------------------------------------------------- | ---- | ---- | ---------------------------- |
| displayId | number | 是 | 否 | 当前物理屏幕id。 |
| regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | 是 | 当前改变所有的系统栏信息。 |
| regionTint | Array<[SystemBarRegionTint](#systembarregiontint8)> | 是 | 是 | 当前已改变的所有系统栏信息。 |
## Rect<sup>7+</sup>
窗口矩形区域。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------ | -------- | ---- | ---- | ------------------ |
......@@ -111,7 +116,7 @@ import window from '@ohos.window';
窗口内容规避区域。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ---------- | ------------- | ---- | ---- | ------------------ |
......@@ -124,7 +129,7 @@ import window from '@ohos.window';
窗口大小。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------ | -------- | ---- | ---- | ---------- |
......@@ -135,7 +140,7 @@ import window from '@ohos.window';
窗口属性。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ------------------------------- | ------------------------- | ---- | ---- | -------------------------------------------- |
......@@ -156,7 +161,7 @@ import window from '@ohos.window';
色域模式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 默认值 | 说明 |
| ---------- | ------ | -------------- |
......@@ -169,32 +174,30 @@ create(id: string, type: WindowType, callback: AsyncCallback&lt;Window&gt;): voi
创建子窗口,使用callback异步回调。
从API version 8开始,此接口废弃,推荐使用[window.create<sup>8+</sup>](#windowcreate8)接口
此接口仅可在FA模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | -------------------------- |
| -------- | -------------------------------------- | ---- | ------------------------------------ |
| id | string | 是 | 窗口id。 |
| type | [WindowType](#windowtype) | 是 | 窗口类型。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回创建的子窗口对象。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前创建的子窗口对象。 |
**示例:**
```js
var windowClass = null;
window.create("first", window.WindowType.TYPE_APP, (err, data) => {
if (err.code) {
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
return;
}
```js
var windowClass = null;
let promise = window.create("first", window.WindowType.TYPE_APP);
promise.then((data)=> {
windowClass = data;
console.info('SubWindow created. Data: ' + JSON.stringify(data))
windowClass.resetSize(500, 1000);
console.info('SubWindow created. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
});
```
```
## window.create<sup>7+</sup>
......@@ -202,7 +205,7 @@ create(id: string, type: WindowType): Promise&lt;Window&gt;
创建子窗口,使用Promise异步回调。
从API version 8开始,此接口废弃,推荐使用[window.create<sup>8+</sup>](#windowcreate8)接口
此接口仅可在FA模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
......@@ -216,21 +219,21 @@ create(id: string, type: WindowType): Promise&lt;Window&gt;
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ------------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前创建的子窗口对象。 |
| -------------------------------- | --------------------------------------- |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
**示例:**
```js
var windowClass = null;
let promise = window.create("first", window.WindowType.TYPE_APP);
promise.then((data)=> {
```js
var windowClass = null;
let promise = window.create("first", window.WindowType.TYPE_APP);
promise.then((data)=> {
windowClass = data;
console.info('SubWindow created. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.info('SubWindow created. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to create the subWindow. Cause: ' + JSON.stringify(err));
});
```
});
```
## window.create<sup>8+</sup>
......@@ -249,22 +252,22 @@ create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback&lt;Wi
| ctx | Context | 是 | 当前应用上下文信息。<br>API version 8的Context定义见[Context](js-apis-Context.md)<br>API version 9的Context定义见[Context](js-apis-service-extension-context.md)。 |
| id | string | 是 | 窗口id。 |
| type | [WindowType](#windowtype) | 是 | 窗口类型。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回当前窗口对象。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前创建的子窗口对象。 |
**示例:**
```js
var windowClass = null;
```js
var windowClass = null;
window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT, (err, data) => {
if (err.code) {
console.error('Failed to create the Window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Window created. Data: ' + JSON.stringify(data))
console.info('Window created. Data: ' + JSON.stringify(data));
windowClass.resetSize(500, 1000);
});
```
});
```
## window.create<sup>8+</sup>
......@@ -287,21 +290,21 @@ create(ctx: Context, id: string, type: WindowType): Promise&lt;Window&gt;
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ----------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前创建的窗口对象。 |
| -------------------------------- | --------------------------------------- |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前创建的子窗口对象。 |
**示例:**
```js
var windowClass = null;
let promise = window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT);
promise.then((data)=> {
```js
var windowClass = null;
let promise = window.create(this.context, "alertWindow", window.WindowType.TYPE_SYSTEM_ALERT);
promise.then((data)=> {
windowClass = data;
console.info('Window created. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed to create the Window. Cause: ' + JSON.stringify(err));
});
```
console.info('Window created. Data:' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to create the Window. Cause:' + JSON.stringify(err));
});
```
## window.find<sup>7+</sup>
......@@ -314,23 +317,23 @@ find(id: string, callback: AsyncCallback&lt;Window&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ---------------------------- |
| -------- | -------------------------------------- | ---- | ------------------------------------ |
| id | string | 是 | 窗口id。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回当前查找的窗口对象。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前查找到的窗口对象。 |
**示例:**
```js
var windowClass = null;
```js
var windowClass = null;
window.find("alertWindow", (err, data) => {
if (err.code) {
console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('window found. Data: ' + JSON.stringify(data))
});
```
console.info('window found. Data: ' + JSON.stringify(data));
});
```
## window.find<sup>7+</sup>
......@@ -349,21 +352,21 @@ find(id: string): Promise&lt;Window&gt;
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ----------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前查找的窗口对象。 |
| -------------------------------- | ------------------------------------- |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前查找的窗口对象。 |
**示例:**
```js
var windowClass = null;
let promise = window.find("alertWindow");
promise.then((data)=> {
```js
var windowClass = null;
let promise = window.find("alertWindow");
promise.then((data)=> {
windowClass = data;
console.info('window found. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.info('window found. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to find the Window. Cause: ' + JSON.stringify(err));
});
```
});
```
## window.getTopWindow
......@@ -371,29 +374,29 @@ getTopWindow(callback: AsyncCallback&lt;Window&gt;): void
获取当前应用内最后显示的窗口,使用callback异步回调。
从API version 8开始,此接口废弃,推荐使用[window.getTopWindow<sup>8+</sup>](#windowgettopwindow8)接口
此接口仅可在FA模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回当前应用内最后显示的窗口对象。 |
| -------- | -------------------------------------- | ---- | -------------------------------------------- |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 |
**示例:**
```js
var windowClass = null;
window.getTopWindow((err, data) => {
```js
var windowClass = null;
window.getTopWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
});
```
});
```
## window.getTopWindow
......@@ -401,28 +404,28 @@ getTopWindow(): Promise&lt;Window&gt;
获取当前应用内最后显示的窗口,使用Promise异步回调。
从API version 8开始,此接口废弃,推荐使用[window.getTopWindow<sup>8+</sup>](#windowgettopwindow8)接口
此接口仅可在FA模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| -------------------------------- | --------------------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前应用内最后显示的窗口对象。 |
| -------------------------------- | ----------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
**示例:**
```js
var windowClass = null;
let promise = window.getTopWindow();
promise.then((data)=> {
```js
var windowClass = null;
let promise = window.getTopWindow();
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
})
```
})
```
## window.getTopWindow<sup>8+</sup>
......@@ -430,6 +433,8 @@ getTopWindow(ctx: Context, callback: AsyncCallback&lt;Window&gt;): void
获取当前应用内最后显示的窗口,使用callback异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
......@@ -437,21 +442,21 @@ getTopWindow(ctx: Context, callback: AsyncCallback&lt;Window&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| ctx | Context | 是 | 当前应用上下文信息。<br>API version 8的Context定义见[Context](js-apis-Context.md)<br>API version 9的Context定义见[Context](js-apis-ability-context.md)。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回当前应用内最后显示的窗口对象。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前应用内最后显示的窗口对象。 |
**示例:**
```js
var windowClass = null;
window.getTopWindow(this.context, (err, data) => {
```js
var windowClass = null;
window.getTopWindow(this.context, (err, data) => {
if (err.code) {
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
});
```
});
```
## window.getTopWindow<sup>8+</sup>
......@@ -459,6 +464,8 @@ getTopWindow(ctx: Context): Promise&lt;Window&gt;
获取当前应用内最后显示的窗口,使用Promise异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
......@@ -470,27 +477,27 @@ getTopWindow(ctx: Context): Promise&lt;Window&gt;
**返回值:**
| 类型 | 说明 |
| -------------------------------- | --------------------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前应用内最后显示的窗口对象。 |
| -------------------------------- | ----------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前应用内最后显示的窗口对象。 |
**示例:**
```js
var windowClass = null;
let promise = window.getTopWindow(this.context);
promise.then((data)=> {
```js
var windowClass = null;
let promise = window.getTopWindow(this.context);
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
})
```
})
```
## on('systemBarTintChange')<sup>8+</sup>
on(type: 'systemBarTintChange', callback: Callback&lt;SystemBarTintState&gt;): void
注册状态栏、导航栏的监听函数
开启状态栏、导航栏属性变化的监听
此接口为系统接口,三方应用不支持调用。
......@@ -501,22 +508,21 @@ on(type: 'systemBarTintChange', callback: Callback&lt;SystemBarTintState&gt;): v
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 |
| callback | Callback&lt;[SystemBarTintState](#systembartintstate)&gt; | 是 | 回调返回监听到的信息。 |
| callback | Callback&lt;[SystemBarTintState](#systembartintstate)&gt; | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 |
**示例:**
```js
var type = 'systemBarTintChange';
windowClass.on(type, (data) => {
```js
window.on('systemBarTintChange', (data) => {
console.info('Succeeded in enabling the listener for systemBarTint changes. Data: ' + JSON.stringify(data));
});
```
});
```
## off('systemBarTintChange')<sup>8+</sup>
off(type: 'systemBarTintChange', callback?: Callback&lt;SystemBarTintState &gt;): void
关闭监听。
关闭状态栏、导航栏属性变化的监听。
此接口为系统接口,三方应用不支持调用。
......@@ -527,17 +533,18 @@ off(type: 'systemBarTintChange', callback?: Callback&lt;SystemBarTintState &gt;)
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 |
| callback | Callback&lt;[SystemBarTintState](#systembartintstate)&gt; | 否 | 回调返回监听到的信息。 |
| callback | Callback&lt;[SystemBarTintState](#systembartintstate)&gt; | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。 |
**示例:**
```js
var type = 'systemBarTintChange';
windowClass.off(type);
```
```js
window.off('systemBarTintChange');
```
## Window
当前窗口实例,窗口管理器管理的基本单元。
下列API示例中都需先使用[getTopWindow()](#windowgettopwindow)[create()](#windowcreate7)[find()](#windowfind7)中的任一方法获取到Window实例,再通过此实例调用对应方法。
### hide<sup>7+</sup>
......@@ -558,15 +565,15 @@ hide (callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
windowClass.hide((err, data) => {
```js
windowClass.hide((err, data) => {
if (err.code) {
console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
return;
}
console.info('window hidden. data: ' + JSON.stringify(data))
})
```
console.info('window hidden. data: ' + JSON.stringify(data));
})
```
### hide<sup>7+</sup>
......@@ -581,19 +588,19 @@ hide(): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.hide();
promise.then((data)=> {
console.info('window hidden. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.hide();
promise.then((data)=> {
console.info('window hidden. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to hide the window. Cause: ' + JSON.stringify(err));
})
```
})
```
### show<sup>7+</sup>
......@@ -611,15 +618,15 @@ show(callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
windowClass.show((err, data) => {
```js
windowClass.show((err, data) => {
if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data))
})
```
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data));
})
```
### show<sup>7+</sup>
......@@ -632,19 +639,19 @@ show(): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.show();
promise.then((data)=> {
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.show();
promise.then((data)=> {
console.info('Succeeded in showing the window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
})
```
})
```
### destroy<sup>7+</sup>
......@@ -662,15 +669,15 @@ destroy(callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
windowClass.destroy((err, data) => {
```js
windowClass.destroy((err, data) => {
if (err.code) {
console.error('Failed to destroy the window. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data))
})
```
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data));
})
```
### destroy<sup>7+</sup>
......@@ -683,19 +690,19 @@ destroy(): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.destroy();
promise.then((data)=> {
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.destroy();
promise.then((data)=> {
console.info('Succeeded in destroying the window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
})
```
})
```
### moveTo<sup>7+</sup>
......@@ -715,16 +722,16 @@ moveTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
windowClass.moveTo(300, 300, (err, data)=>{
```js
windowClass.moveTo(300, 300, (err, data)=>{
if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return;
}
console.info('Window moved. Data: ' + JSON.stringify(data))
console.info('Window moved. Data: ' + JSON.stringify(data));
});
```
});
```
### moveTo<sup>7+</sup>
......@@ -744,19 +751,19 @@ moveTo(x: number, y: number): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.moveTo(300, 300);
promise.then((data)=> {
console.info('Window moved. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.moveTo(300, 300);
promise.then((data)=> {
console.info('Window moved. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to move the window. Cause: ' + JSON.stringify(err));
})
```
})
```
### resetSize<sup>7+</sup>
......@@ -776,15 +783,15 @@ resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): v
**示例:**
```js
windowClass.resetSize(500, 1000, (err, data) => {
```js
windowClass.resetSize(500, 1000, (err, data) => {
if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return;
}
console.info('Window size changed. Data: ' + JSON.stringify(data))
});
```
console.info('Window size changed. Data: ' + JSON.stringify(data));
});
```
### resetSize<sup>7+</sup>
......@@ -804,19 +811,19 @@ resetSize(width: number, height: number): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.resetSize(500, 1000);
promise.then((data)=> {
console.info('Window size changed. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.resetSize(500, 1000);
promise.then((data)=> {
console.info('Window size changed. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to change the window size. Cause: ' + JSON.stringify(err));
});
```
});
```
### setWindowType<sup>7+</sup>
......@@ -837,16 +844,16 @@ setWindowType(type: WindowType, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
var type = window.TYPE_APP;
windowClass.setWindowType(type, (err, data) => {
```js
var type = window.WindowType.TYPE_APP;
windowClass.setWindowType(type, (err, data) => {
if (err.code) {
console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data))
});
```
console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data));
});
```
### setWindowType<sup>7+</sup>
......@@ -867,20 +874,20 @@ setWindowType(type: WindowType): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var type = window.TYPE_APP;
let promise = windowClass.setWindowType(type);
promise.then((data)=> {
console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var type = window.WindowType.TYPE_APP;
let promise = windowClass.setWindowType(type);
promise.then((data)=> {
console.info('Succeeded in setting the window type. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the window type. Cause: ' + JSON.stringify(err));
});
```
});
```
### getProperties
......@@ -893,20 +900,20 @@ getProperties(callback: AsyncCallback&lt;WindowProperties&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback&lt;[WindowProperties](#windowproperties)&gt; | 是 | 回调返回窗口属性。 |
| -------- | ---------------------------------------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;[WindowProperties](#windowproperties)&gt; | 是 | 回调函数。返回当前窗口属性。 |
**示例:**
```js
windowClass.getProperties((err, data) => {
```js
windowClass.getProperties((err, data) => {
if (err.code) {
console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
});
```
});
```
### getProperties
......@@ -919,19 +926,19 @@ getProperties(): Promise&lt;WindowProperties&gt;
**返回值:**
| 类型 | 说明 |
| ---------------------------------------------------- | ------------------------------------- |
| Promise&lt;[WindowProperties](#windowproperties)&gt; | 以Promise形式返回结果,返回窗口属性。 |
| ---------------------------------------------------- | ------------------------------- |
| Promise&lt;[WindowProperties](#windowproperties)&gt; | Promise对象。返回当前窗口属性。 |
**示例:**
```js
let promise = windowClass.getProperties();
promise.then((data)=> {
console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.getProperties();
promise.then((data)=> {
console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
});
```
});
```
### getAvoidArea<sup>7+</sup>
......@@ -946,20 +953,20 @@ getAvoidArea(type: AvoidAreaType, callback: AsyncCallback&lt;AvoidArea&gt;): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | [AvoidAreaType](#avoidareatype) | 是 | 表示规避区类型。type为TYPE_SYSTEM,表示系统默认区域。type为TYPE_CUTOUT,表示刘海屏区域。 |
| callback | AsyncCallback&lt;[AvoidArea](#avoidarea)&gt; | 是 | 回调返回窗口内容规避区域。 |
| callback | AsyncCallback&lt;[AvoidArea](#avoidarea)&gt; | 是 | 回调函数。返回窗口内容规避区域。 |
**示例:**
```js
var type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err, data) => {
```js
var type = window.AvoidAreaType.TYPE_SYSTEM;
windowClass.getAvoidArea(type, (err, data) => {
if (err.code) {
console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
});
```
});
```
### getAvoidArea<sup>7+</sup>
......@@ -978,19 +985,19 @@ getAvoidArea(type: AvoidAreaType): Promise&lt;AvoidArea&gt;
**返回值:**
| 类型 | 说明 |
| -------------------------------------- | --------------------------------------------- |
| Promise&lt;[AvoidArea](#avoidarea)&gt; | 以Promise形式返回结果,返回窗口内容规避区域。 |
| -------------------------------------- | ----------------------------------- |
| Promise&lt;[AvoidArea](#avoidarea)&gt; | Promise对象。返回窗口内容规避区域。 |
**示例:**
```js
let promise = windowClass.getAvoidArea();
promise.then((data)=> {
console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.getAvoidArea();
promise.then((data)=> {
console.info('Succeeded in obtaining the area. Data:' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the area. Cause:' + JSON.stringify(err));
});
```
});
```
### setFullScreen
......@@ -1009,16 +1016,16 @@ setFullScreen(isFullScreen: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
var isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => {
```js
var isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data))
});
```
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});
```
### setFullScreen
......@@ -1037,20 +1044,20 @@ setFullScreen(isFullScreen: boolean): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var isFullScreen = true;
let promise = windowClass.setFullScreen(isFullScreen);
promise.then((data)=> {
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var isFullScreen = true;
let promise = windowClass.setFullScreen(isFullScreen);
promise.then((data)=> {
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
});
```
});
```
### setLayoutFullScreen<sup>7+</sup>
......@@ -1069,16 +1076,16 @@ setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback&lt;void
**示例:**
```js
var isLayoutFullScreen= true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => {
```js
var isLayoutFullScreen= true;
windowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data))
});
```
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
});
```
### setLayoutFullScreen<sup>7+</sup>
......@@ -1097,20 +1104,20 @@ setLayoutFullScreen(isLayoutFullScreen: boolean): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var isLayoutFullScreen = true;
let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
promise.then((data)=> {
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var isLayoutFullScreen = true;
let promise = windowClass.setLayoutFullScreen(isLayoutFullScreen);
promise.then((data)=> {
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
});
```
});
```
### setSystemBarEnable<sup>7+</sup>
......@@ -1124,21 +1131,21 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| names | Array | 是 | 设置状态栏和导航栏是否显示。例如,需全部显示,该参数设置为["status",&nbsp;"navigation"], 不设置,则默认不显示。 |
| names | Array | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为["status",&nbsp;"navigation"];不设置,则默认不显示。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
var names = ["status", "navigation"];
windowClass.setSystemBarEnable(names, (err, data) => {
```js
var names = ["status", "navigation"];
windowClass.setSystemBarEnable(names, (err, data) => {
if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data))
});
```
console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data));
});
```
### setSystemBarEnable<sup>7+</sup>
......@@ -1152,25 +1159,25 @@ setSystemBarEnable(names: Array<'status' | 'navigation'>): Promise&lt;void&gt;
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----- | ---- | ------------------------------------------------------------ |
| names | Array | 是 | 设置状态栏和导航栏是否显示。例如,需全部显示,该参数设置为["status",&nbsp;"navigation"], 不设置,则默认不显示。 |
| names | Array | 是 | 设置状态栏和导航栏是否显示。<br>例如,需全部显示,该参数设置为["status",&nbsp;"navigation"];不设置,则默认不显示。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var names = ["status", "navigation"];
let promise = windowClass.setSystemBarEnable(names);
promise.then((data)=> {
console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var names = ["status", "navigation"];
let promise = windowClass.setSystemBarEnable(names);
promise.then((data)=> {
console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
});
```
});
```
### setSystemBarProperties
......@@ -1183,14 +1190,14 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: Async
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------- | ------------------------------------------- | ---- | -------------------- |
| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏状态栏的属性。 |
| ------------------- | ------------------------------------------- | ---- | ---------------------- |
| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏状态栏的属性。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
var SystemBarProperties={
```js
var SystemBarProperties={
statusBarColor: '#ff00ff',
navigationBarColor: '#00ff00',
//以下两个属性从API Version7开始支持
......@@ -1199,15 +1206,15 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: Async
//以下两个属性从API Version8开始支持
statusBarContentColor:'#ffffff',
navigationBarContentColor:'#00ffff'
};
windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => {
};
windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => {
if (err.code) {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data))
});
```
console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data));
});
```
### setSystemBarProperties
......@@ -1220,19 +1227,19 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;voi
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------------- | ------------------------------------------- | ---- | -------------------- |
| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏状态栏的属性。 |
| ------------------- | ------------------------------------------- | ---- | ---------------------- |
| SystemBarProperties | [SystemBarProperties](#systembarproperties) | 是 | 导航栏状态栏的属性。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var SystemBarProperties={
```js
var SystemBarProperties={
statusBarColor: '#ff00ff',
navigationBarColor: '#00ff00',
//以下两个属性从API Version7开始支持
......@@ -1241,20 +1248,20 @@ setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise&lt;voi
//以下两个属性从API Version8开始支持
statusBarContentColor:'#ffffff',
navigationBarContentColor:'#00ffff'
};
let promise = windowClass.setSystemBarProperties(SystemBarProperties);
promise.then((data)=> {
console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data))
}).catch((err)=>{
};
let promise = windowClass.setSystemBarProperties(SystemBarProperties);
promise.then((data)=> {
console.info('Succeeded in setting the system bar properties. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
});
```
});
```
### loadContent<sup>7+</sup>
loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
当前窗口加载具体页面内容,使用callback异步回调。
当前窗口加载具体页面内容,使用callback异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
......@@ -1267,21 +1274,21 @@ loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
windowClass.loadContent("pages/page2/page2", (err, data) => {
```js
windowClass.loadContent("pages/page2/page2", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
```
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
```
### loadContent<sup>7+</sup>
loadContent(path: string): Promise&lt;void&gt;
当前窗口加载具体页面内容,使用Promise异步回调。
当前窗口加载具体页面内容,使用Promise异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
......@@ -1294,122 +1301,200 @@ loadContent(path: string): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.loadContent("pages/page2/page2");
promise.then((data)=> {
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.loadContent("pages/page2/page2");
promise.then((data)=> {
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
});
```
});
```
### loadContent<sup>9+</sup>
### isShowing<sup>7+</sup>
loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
isShowing(callback: AsyncCallback&lt;boolean&gt;): void
为当前窗口加载与LocalStorage相关联的具体页面内容,使用callback异步回调。
判断当前窗口是否已显示,使用callback异步回调
此接口仅可在Stage模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数返回是否显示子窗口结果。 |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 设置加载页面的路径。 |
| storage | [LocalStorage](../ui/ui-ts-local-storage.md) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
windowClass.isShowing((err, data) => {
```ts
class myAbility extends Ability {
storage : LocalStorage
onWindowStageCreate(windowStage) {
this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121);
console.log('onWindowStageCreate');
windowStage.loadContent("pages/page2",this.storage,(err, data) => {
if (err.code) {
console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err));
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data))
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
```
}
}
```
### isShowing<sup>7+</sup>
### loadContent<sup>9+</sup>
isShowing(): Promise&lt;boolean&gt;
loadContent(path: string, storage: LocalStorage): Promise&lt;void&gt;
判断当前窗口是否已显示,使用Promise异步回调。
为当前窗口加载与LocalStorage相关联的具体页面内容,使用Promise异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 设置加载页面的路径。 |
| storage | [LocalStorage](../ui/ui-ts-local-storage.md) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 |
**返回值:**
| 类型 | 说明 |
| ---------------------- | ----------------------------------------------------- |
| Promise&lt;boolean&gt; | 以Promise形式返回结果,返回当前窗口是否已显示的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.isShowing();
```ts
class myAbility extends Ability {
storage : LocalStorage
onWindowStageCreate(windowStage) {
this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121);
console.log('onWindowStageCreate');
var windowClass = null;
let promise = windowStage.loadContent("pages/page2",this.storage);
promise.then((data)=> {
console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data))
windowClass = data;
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err));
});
```
### on('windowSizeChange')<sup>7+</sup>
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
})
}
}
```
### isShowing<sup>7+</sup>
on(type: 'windowSizeChange', callback: Callback&lt;Size&gt;): void
isShowing(callback: AsyncCallback&lt;boolean&gt;): void
开启监听
判断当前窗口是否已显示,使用callback异步回调
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
| callback | Callback&lt;[Size](#size)&gt; | 是 | 回调返回监听到的信息。 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。返回true表示当前窗口已显示,返回false则表示当前窗口未显示。 |
**示例:**
```js
var type = 'windowSizeChange';
windowClass.on(type, (data) => {
console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
});
```
```js
windowClass.isShowing((err, data) => {
if (err.code) {
console.error('Failed to check whether the window is showing. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
});
```
### off('windowSizeChange')<sup>7+</sup>
### isShowing<sup>7+</sup>
off(type: 'windowSizeChange', callback?: Callback&lt;Size &gt;): void
isShowing(): Promise&lt;boolean&gt;
关闭监听
判断当前窗口是否已显示,使用Promise异步回调
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
| callback | Callback&lt;[Size](#size)&gt; | 否 | 回调返回监听到的信息。 |
**返回值:**
| 类型 | 说明 |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口已显示,返回false则表示当前窗口未显示。 |
**示例:**
```js
var type = 'windowSizeChange';
windowClass.off(type);
```
```js
let promise = windowClass.isShowing();
promise.then((data)=> {
console.info('Succeeded in checking whether the window is showing. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to check whether the window is showing. Cause: ' + JSON.stringify(err));
});
```
### on('windowSizeChange')<sup>7+</sup>
on(type: 'windowSizeChange', callback: Callback&lt;Size&gt;): void
开启窗口尺寸变化的监听。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | -------------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
| callback | Callback&lt;[Size](#size7)&gt; | 是 | 回调函数。返回当前的窗口尺寸。 |
**示例:**
```js
windowClass.on('windowSizeChange', (data) => {
console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
});
```
### off('windowSizeChange')<sup>7+</sup>
off(type: 'windowSizeChange', callback?: Callback&lt;Size &gt;): void
关闭窗口尺寸变化的监听。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------- | ---- | -------------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'windowSizeChange',即窗口尺寸变化事件。 |
| callback | Callback&lt;[Size](#size)&gt; | 否 | 回调函数。返回当前的窗口尺寸。 |
**示例:**
```js
windowClass.off('windowSizeChange');
```
### on('systemAvoidAreaChange')<sup>7+</sup>
on(type: 'systemAvoidAreaChange', callback: Callback&lt;AvoidArea&gt;): void
开启监听。
开启系统窗口规避区变化的监听。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
......@@ -1418,22 +1503,21 @@ on(type: 'systemAvoidAreaChange', callback: Callback&lt;AvoidArea&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统窗口规避区变化事件。 |
| callback | Callback&lt;[AvoidArea](#avoidarea)&gt; | 是 | 回调返回监听到的信息。 |
| callback | Callback&lt;[AvoidArea](#avoidarea)&gt; | 是 | 回调函数。返回当前的窗口规避区。 |
**示例:**
```js
var type = 'systemAvoidAreaChange';
windowClass.on(type, (data) => {
```js
windowClass.on('systemAvoidAreaChange', (data) => {
console.info('Succeeded in enabling the listener for system avoid area changes. Data: ' + JSON.stringify(data));
});
```
});
```
### off('systemAvoidAreaChange')<sup>7+</sup>
off(type: 'systemAvoidAreaChange', callback?: Callback&lt;AvoidArea&gt;): void
关闭监听。
关闭系统窗口规避区变化的监听。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
......@@ -1442,14 +1526,13 @@ off(type: 'systemAvoidAreaChange', callback?: Callback&lt;AvoidArea&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'systemAvoidAreaChange',即系统窗口规避区变化事件。 |
| callback | Callback&lt;[AvoidArea](#avoidarea)&gt; | 否 | 回调返回监听到的信息。 |
| callback | Callback&lt;[AvoidArea](#avoidarea)&gt; | 否 | 回调函数。返回当前的窗口规避区。 |
**示例:**
```js
var type = 'systemAvoidAreaChange';
windowClass.off(type);
```
```js
windowClass.off('systemAvoidAreaChange');
```
### on('keyboardHeightChange')<sup>7+</sup>
......@@ -1462,18 +1545,17 @@ on(type: 'keyboardHeightChange', callback: Callback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | ------------------------------------------------------------ |
| -------- | ------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
| callback | Callbacknumber&gt; | 是 | 回调返回监听到的信息。 |
| callback | Callback<number&gt; | 是 | 回调函数。返回当前的键盘高度。 |
**示例:**
```js
var type = 'keyboardHeightChange';
windowClass.on(type, (data) => {
```js
windowClass.on('keyboardHeightChange', (data) => {
console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data));
});
```
});
```
### off('keyboardHeightChange')<sup>7+</sup>
......@@ -1488,14 +1570,13 @@ off(type: 'keyboardHeightChange', callback?: Callback&lt;number&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'keyboardHeightChange',即键盘高度变化事件。 |
| callback | Callback&lt;number&gt; | 否 | 回调返回监听到的信息。 |
| callback | Callback&lt;number&gt; | 否 | 回调函数。返回当前的键盘高度。 |
**示例:**
```js
var type = 'keyboardHeightChange';
windowClass.off(type);
```
```js
windowClass.off('keyboardHeightChange');
```
### isSupportWideGamut<sup>8+</sup>
......@@ -1508,20 +1589,20 @@ isSupportWideGamut(callback: AsyncCallback&lt;boolean&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数返回是否支持广色域模式。 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。返回true表示当前窗口支持广色域模式,返回false则表示当前窗口不支持广色域模式。 |
**示例:**
```js
windowClass.isSupportWideGamut((err, data) => {
```js
windowClass.isSupportWideGamut((err, data) => {
if (err.code) {
console.error('Failed to check whether the window support WideGamut. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data))
})
```
console.info('Succeeded in checking whether the window support WideGamut Data: ' + JSON.stringify(data));
})
```
### isSupportWideGamut<sup>8+</sup>
......@@ -1535,18 +1616,18 @@ isSupportWideGamut(): Promise&lt;boolean&gt;
| 类型 | 说明 |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | 以Promise形式返回结果,返回当前窗口是否支持广色域模式的结果。 |
| Promise&lt;boolean&gt; | Promise对象。返回true表示当前窗口支持广色域模式,返回false则表示当前窗口不支持广色域模式。 |
**示例:**
```js
let promise = windowClass.isSupportWideGamut();
promise.then((data)=> {
console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.isSupportWideGamut();
promise.then((data)=> {
console.info('Succeeded in checking whether the window support WideGamut. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to check whether the window support WideGamut. Cause: ' + JSON.stringify(err));
});
```
});
```
### setColorSpace<sup>8+</sup>
......@@ -1565,15 +1646,15 @@ setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err, data) => {
```js
windowClass.setColorSpace(window.ColorSpace.WIDE_GAMUT, (err, data) => {
if (err.code) {
console.error('Failed to set window colorspace. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data))
})
```
console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data));
})
```
### setColorSpace<sup>8+</sup>
......@@ -1586,25 +1667,25 @@ setColorSpace(colorSpace:ColorSpace): Promise&lt;void&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------- | ---- | ------------ |
| colorSpace | [ColorSpace](#colorspace) | 是 | 设置色域模式 |
| ---------- | ------------------------- | ---- | -------------- |
| colorSpace | [ColorSpace](#colorspace) | 是 | 设置色域模式 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.isSupportWideGamut(window.ColorSpace.WIDE_GAMUT);
promise.then((data)=> {
console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.isSupportWideGamut(window.ColorSpace.WIDE_GAMUT);
promise.then((data)=> {
console.info('Succeeded in setting window colorspace. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set window colorspace. Cause: ' + JSON.stringify(err));
});
```
});
```
### getColorSpace<sup>8+</sup>
......@@ -1617,20 +1698,20 @@ getColorSpace(callback: AsyncCallback&lt;ColorSpace&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;[ColorSpace](#colorspace)&gt; | 是 | 回调函数返回当前色域模式。 |
| -------- | ---------------------------------------------- | ---- | ---------------------------------------------------------- |
| callback | AsyncCallback&lt;[ColorSpace](#colorspace)&gt; | 是 | 回调函数。当获取成功,err为undefined,data为当前色域模式。 |
**示例:**
```js
windowClass.getColorSpace((err, data) => {
```js
windowClass.getColorSpace((err, data) => {
if (err.code) {
console.error('Failed to get window colorspace. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data))
})
```
console.info('Succeeded in getting window colorspace. Cause:' + JSON.stringify(data));
})
```
### getColorSpace<sup>8+</sup>
......@@ -1643,19 +1724,19 @@ getColorSpace(): Promise&lt;ColorSpace&gt;
**返回值:**
| 类型 | 说明 |
| ---------------------------------------- | ----------------------------------------- |
| Promise&lt;[ColorSpace](#colorspace)&gt; | 以Promise形式返回结果,返回当前色域模式。 |
| ---------------------------------------- | ------------------------------- |
| Promise&lt;[ColorSpace](#colorspace)&gt; | Promise对象。返回当前色域模式。 |
**示例:**
```js
let promise = windowClass.getColorSpace();
promise.then((data)=> {
console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.getColorSpace();
promise.then((data)=> {
console.info('Succeeded in getting window color space. Cause:' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to get window colorspace. Cause: ' + JSON.stringify(err));
});
```
});
```
### setBackgroundColor
......@@ -1669,21 +1750,21 @@ setBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| color | string | 是 | 需要设置的背景色,为十六进制颜色,不区分大小写,例如"#00FF00"或"#FF00FF00"。 |
| color | string | 是 | 需要设置的背景色,为十六进制颜色,不区分大小写,例如`#00FF00``#FF00FF00`。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
var color = '#00ff33';
windowClass.setBackgroundColor(color, (err, data) => {
```js
var color = '#00ff33';
windowClass.setBackgroundColor(color, (err, data) => {
if (err.code) {
console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data));
});
```
});
```
### setBackgroundColor
......@@ -1702,20 +1783,20 @@ setBackgroundColor(color: string): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var color = '#00ff33';
let promise = windowClass.setBackgroundColor(color);
promise.then((data)=> {
console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var color = '#00ff33';
let promise = windowClass.setBackgroundColor(color);
promise.then((data)=> {
console.info('Succeeded in setting the background color. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the background color. Cause: ' + JSON.stringify(err));
});
```
});
```
### setBrightness
......@@ -1734,16 +1815,16 @@ setBrightness(brightness: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
var brightness = 1;
windowClass.setBrightness(brightness, (err, data) => {
```js
var brightness = 1;
windowClass.setBrightness(brightness, (err, data) => {
if (err.code) {
console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data));
});
```
});
```
### setBrightness
......@@ -1762,26 +1843,26 @@ setBrightness(brightness: number): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var brightness = 1;
let promise = windowClass.setBrightness(brightness);
promise.then((data)=> {
console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var brightness = 1;
let promise = windowClass.setBrightness(brightness);
promise.then((data)=> {
console.info('Succeeded in setting the brightness. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the brightness. Cause: ' + JSON.stringify(err));
});
```
});
```
### setDimBehind<sup>(deprecated)</sup>
setDimBehind(dimBehindValue: number, callback: AsyncCallback&lt;void&gt;): void
窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback方式作为异步方法
窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用callback异步回调
> **说明:** 从API version 9开始废弃。
>
......@@ -1791,28 +1872,28 @@ setDimBehind(dimBehindValue: number, callback: AsyncCallback&lt;void&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------------------------- | ---- | -------------------------------------------------- |
| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------------------------- | ---- | -------------------------------------------------- |
| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
windowClass.setDimBehind(0.5, (err, data) => {
```js
windowClass.setDimBehind(0.5, (err, data) => {
if (err.code) {
console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the dimness. Data:' + JSON.stringify(data));
});
```
});
```
### setDimBehind<sup>(deprecated)</sup>
setDimBehind(dimBehindValue: number): Promise&lt;void&gt;
窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise方式作为异步方法
窗口叠加时,设备有子窗口的情况下设置靠后的窗口的暗度值,使用Promise异步回调
> **说明:** 从API version 9开始废弃。
>
......@@ -1822,26 +1903,26 @@ setDimBehind(dimBehindValue: number): Promise&lt;void&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------ | ---- | -------------------------------------------------- |
| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------ | ---- | -------------------------------------------------- |
| dimBehindValue | number | 是 | 表示靠后的窗口的暗度值,取值范围为0-1,1表示最暗。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let promise = windowClass.setDimBehind(0.5);
promise.then((data)=> {
console.info('Succeeded in setting the dimness. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
let promise = windowClass.setDimBehind(0.5);
promise.then((data)=> {
console.info('Succeeded in setting the dimness. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the dimness. Cause: ' + JSON.stringify(err));
});
```
});
```
### setFocusable<sup>7+</sup>
......@@ -1860,16 +1941,16 @@ setFocusable(isFocusable: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
var isFocusable= true;
windowClass.setFocusable(isFocusable, (err, data) => {
```js
var isFocusable= true;
windowClass.setFocusable(isFocusable, (err, data) => {
if (err.code) {
console.error('Failed to set the window to be focusable. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data));
});
```
});
```
### setFocusable<sup>7+</sup>
......@@ -1888,20 +1969,20 @@ setFocusable(isFocusable: boolean): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var isFocusable= true;
let promise = windowClass.setFocusable(isFocusable);
promise.then((data)=> {
console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var isFocusable= true;
let promise = windowClass.setFocusable(isFocusable);
promise.then((data)=> {
console.info('Succeeded in setting the window to be focusable. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the window to be focusable. Cause: ' + JSON.stringify(err));
});
```
});
```
### setKeepScreenOn
......@@ -1920,53 +2001,54 @@ setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback&lt;void&gt;): v
**示例:**
```js
var isKeepScreenOn = true;
windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => {
```js
var isKeepScreenOn = true;
windowClass.setKeepScreenOn(isKeepScreenOn, (err, data) => {
if (err.code) {
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data));
});
```
### setOutsideTouchable<sup>(deprecated)</sup>
});
```
setOutsideTouchable(touchable: boolean, callback: AsyncCallback&lt;void&gt;): void
### setKeepScreenOn
设置是否允许可点击子窗口以外的区域,使用callback方式作为异步方法。
setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
> **说明:** 从API version 9开始废弃。
>
> 从 API version 7开始支持。
设置屏幕是否为常亮状态,使用Promise异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------- |
| touchable | boolean | 是 | 设置是否可点击。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------- | ---- | ------------------------ |
| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
windowClass.setOutsideTouchable(true, (err, data) => {
if (err.code) {
console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data))
})
```
```js
var isKeepScreenOn = true;
let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
promise.then((data) => {
console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.info('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
});
```
### setOutsideTouchable<sup>(deprecated)</sup>
setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;
setOutsideTouchable(touchable: boolean, callback: AsyncCallback&lt;void&gt;): void
设置是否允许可点击子窗口以外的区域,使用Promise方式作为异步方法
设置是否允许可点击子窗口之外的区域,使用callback异步回调
> **说明:** 从API version 9开始废弃。
>
......@@ -1976,58 +2058,57 @@ setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------- | ---- | ---------------- |
| touchable | boolean | 是 | 设置是否可点击。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------- |
| touchable | boolean | 是 | 设置是否可点击。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
let promise = windowClass.setOutsideTouchable(true);
promise.then((data)=> {
console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
windowClass.setOutsideTouchable(true, (err, data) => {
if (err.code) {
console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));
});
```
return;
}
console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data));
})
```
### setKeepScreenOn
### setOutsideTouchable<sup>(deprecated)</sup>
setKeepScreenOn(isKeepScreenOn: boolean): Promise&lt;void&gt;
setOutsideTouchable(touchable: boolean): Promise&lt;void&gt;
设置屏幕是否为常亮状态,使用Promise异步回调。
设置是否允许可点击子窗口之外的区域,使用Promise异步回调。。
> **说明:** 从API version 9开始废弃。
>
> 从 API version 7开始支持。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------- | ---- | ------------------------ |
| isKeepScreenOn | boolean | 是 | 设置屏幕是否为常亮状态。 |
| --------- | ------- | ---- | ---------------- |
| touchable | boolean | 是 | 设置是否可点击。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var isKeepScreenOn= true;
let promise = windowClass.setKeepScreenOn(isKeepScreenOn);
promise.then((data)=> {
console.info('Succeeded in setting the screen to be always on. Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
});
```
```js
let promise = windowClass.setOutsideTouchable(true);
promise.then((data)=> {
console.info('Succeeded in setting the area to be touchable. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the area to be touchable. Cause: ' + JSON.stringify(err));
});
```
### setPrivacyMode<sup>7+</sup>
......@@ -2046,17 +2127,17 @@ setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback&lt;void&gt;): voi
**示例:**
```js
var isPrivacyMode = true;
windowClass.setPrivacyMode(isPrivacyMode, (err, data) => {
```js
var isPrivacyMode = true;
windowClass.setPrivacyMode(isPrivacyMode, (err, data) => {
if (err.code) {
console.error('Failed to set the window to privacy mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window to privacy mode. Data:' + JSON.stringify(data));
});
```
});
```
### setPrivacyMode<sup>7+</sup>
......@@ -2075,20 +2156,20 @@ setPrivacyMode(isPrivacyMode: boolean): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var isPrivacyMode = true;
let promise = windowClass.setPrivacyMode(isPrivacyMode);
promise.then((data)=> {
console.info('Succeeded in setting the window to privacy mode. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var isPrivacyMode = true;
let promise = windowClass.setPrivacyMode(isPrivacyMode);
promise.then((data)=> {
console.info('Succeeded in setting the window to privacy mode. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the window to privacy mode. Cause: ' + JSON.stringify(err));
});
```
});
```
### setTouchable<sup>7+</sup>
......@@ -2107,17 +2188,17 @@ setTouchable(isTouchable: boolean, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
var isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => {
```js
var isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => {
if (err.code) {
console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window to be touchable. Data:' + JSON.stringify(data));
});
```
});
```
### setTouchable<sup>7+</sup>
......@@ -2136,109 +2217,156 @@ setTouchable(isTouchable: boolean): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------------- |
| Promise&lt;void&gt; | 以Promise形式返回结果,返回当前函数执行的结果。 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
var isTouchable = true;
let promise = windowClass.setTouchable(isTouchable);
promise.then((data)=> {
console.info('Succeeded in setting the window to be touchable. Data: ' + JSON.stringify(data))
}).catch((err)=>{
```js
var isTouchable = true;
let promise = windowClass.setTouchable(isTouchable);
promise.then((data)=> {
console.info('Succeeded in setting the window to be touchable. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to set the window to be touchable. Cause: ' + JSON.stringify(err));
});
```
});
```
## WindowStageEventType<sup>9+</sup>
WindowStage生命周期。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
| 名称 | 默认值 | 说明 |
| ---------- | ------ | -------- |
| FOREGROUND | 1 | 切到前台 |
| ACTIVE | 2 | 获焦状态 |
| INACTIVE | 3 | 失焦状态 |
| BACKGROUND | 4 | 切到后台 |
| ---------- | ------ | ---------- |
| FOREGROUND | 1 | 切到前台 |
| ACTIVE | 2 | 获焦状态 |
| INACTIVE | 3 | 失焦状态 |
| BACKGROUND | 4 | 切到后台 |
## WindowStage<sup>9+</sup>
窗口管理器。管理各个基本窗口单元,即[Window](#window)实例。
下列API示例中都需在[onWindowStageCreate()](js-apis-application-ability.md#abilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。
### getMainWindow<sup>9+</sup>
getMainWindow(callback: AsyncCallback&lt;Window&gt;): void
获取该WindowStage实例下的主窗口,使用callback异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | --------------------------------------------- |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前WindowStage下的主窗口对象。 |
**示例:**
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var windowClass = null;
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
});
}
}
```
### getMainWindow<sup>9+</sup>
getMainWindow(): Promise&lt;Window&gt;
获取该WindowStage实例下的主窗口,使用Promise异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ---------------------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前WindowStage下的主窗口对象。 |
| -------------------------------- | ------------------------------------------------ |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的主窗口对象。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var windowClass = null;
let promise = windowStage.getMainWindow();
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data))
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
});
}
}
```
}
```
### createSubWindow<sup>9+</sup>
### getMainWindow<sup>9+</sup>
createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void
getMainWindow(callback: AsyncCallback&lt;Window&gt;): void
创建该WindowStage实例下的子窗口,使用callback异步回调。
获取该WindowStage实例下的主窗口,使用callback异步回调
此接口仅可在Stage模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | --------------------------------------- |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回当前WindowStage下的主窗口对象。 |
| -------- | -------------------------------------- | ---- | --------------------------------------------- |
| name | String | 是 | 子窗口的名字。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调函数。返回当前WindowStage下的子窗口对象。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var windowClass = null;
windowStage.getMainWindow((err, data) => {
windowStage.createSubWindow("mySubWindow", (err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
console.error('Failed to create sub window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data));
windowClass.resetSize(500, 1000);
});
}
}
```
}
```
### createSubWindow<sup>9+</sup>
createSubWindow(name: string): Promise&lt;Window&gt;
创建该WindowStage实例下的子窗口,使用Promise异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
......@@ -2250,126 +2378,179 @@ createSubWindow(name: string): Promise&lt;Window&gt;
**返回值:**
| 类型 | 说明 |
| -------------------------------- | ------------------------------------------------- |
| Promise&lt;[Window](#window)&gt; | 以Promise形式返回结果,返回当前创建的子窗口对象。 |
| -------------------------------- | ------------------------------------------------ |
| Promise&lt;[Window](#window)&gt; | Promise对象。返回当前WindowStage下的子窗口对象。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var windowClass = null;
let promise = windowStage.createSubWindow("mySubWindow");
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data))
console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to create sub window. Cause: ' + JSON.stringify(err));
})
}
}
```
}
```
### getSubWindow<sup>9+</sup>
### createSubWindow<sup>9+</sup>
getSubWindow(callback: AsyncCallback&lt;Array&lt;Window&gt;&gt;): void
createSubWindow(name: string, callback: AsyncCallback&lt;Window&gt;): void
获取该WindowStage实例下的所有子窗口,使用callback异步回调。
创建该WindowStage实例下的子窗口,使用callback异步回调
此接口仅可在Stage模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ------------------------------ |
| name | String | 是 | 子窗口的名字。 |
| callback | AsyncCallback&lt;[Window](#window)&gt; | 是 | 回调返回当前创建的子窗口对象。 |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Window](#window)&gt;&gt; | 是 | 回调函数。返回当前WindowStage下的所有子窗口对象。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var windowClass = null;
windowStage.createSubWindow("mySubWindow", (err, data) => {
windowStage.getSubWindow((err, data) => {
if (err.code) {
console.error('Failed to create sub window. Cause: ' + JSON.stringify(err));
console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data));
windowClass.resetSize(500, 1000);
console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data));
});
}
}
```
}
```
### getSubWindow<sup>9+</sup>
getSubWindow(): Promise&lt;Array&lt;Window&gt;&gt;
获取该WindowStage实例下的所有子窗口,使用Promise异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | 以Promise形式返回结果,返回当前WindowStage下的所有子窗口对象。 |
| --------------------------------------------- | ---------------------------------------------------- |
| Promise&lt;Array&lt;[Window](#window)&gt;&gt; | Promise对象。返回当前WindowStage下的所有子窗口对象。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var windowClass = null;
let promise = windowStage.getSubWindow();
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data))
console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err));
})
}
}
```
}
```
### loadContent<sup>9+</sup>
### getSubWindow<sup>9+</sup>
loadContent(path: string, storage: LocalStorage, callback: AsyncCallback&lt;void&gt;): void
getSubWindow(callback: AsyncCallback&lt;Array&lt;Window&gt;&gt;): void
为当前WindowStage的主窗口加载与LocalStorage相关联的具体页面内容,使用callback异步回调。
获取该WindowStage实例下的所有子窗口,使用callback异步回调
此接口仅可在Stage模型下使用
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;[Window](#window)&gt;&gt; | 是 | 回调返回当前WindowStage下的所有子窗口对象。 |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 设置加载页面的路径。 |
| storage | [LocalStorage](../ui/ui-ts-local-storage.md) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
storage : LocalStorage
onWindowStageCreate(windowStage) {
this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121);
console.log('onWindowStageCreate');
var windowClass = null;
windowStage.getSubWindow((err, data) => {
windowStage.loadContent("pages/page2",this.storage,(err, data) => {
if (err.code) {
console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err));
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data));
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
}
}
```
### loadContent<sup>9+</sup>
loadContent(path: string, storage: LocalStorage): Promise&lt;void&gt;
为当前WindowStage的主窗口加载与LocalStorage相关联的具体页面内容,使用Promise异步回调。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 设置加载页面的路径。 |
| storage | [LocalStorage](../ui/ui-ts-local-storage.md) | 是 | 存储单元,为应用程序范围内的可变状态属性和非可变状态属性提供存储。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
storage : LocalStorage
onWindowStageCreate(windowStage) {
this.storage = new LocalStorage();
this.storage.setOrCreate("storageSimpleProp",121);
console.log('onWindowStageCreate');
var windowClass = null;
let promise = windowStage.loadContent("pages/page2",this.storage);
promise.then((data)=> {
windowClass = data;
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
}).catch((err)=>{
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
})
}
```
}
```
### loadContent<sup>9+</sup>
......@@ -2377,7 +2558,9 @@ loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
为当前WindowStage的主窗口加载具体页面内容,使用callback异步回调。
**系统能力:** SystemCapability.WindowManager.WindowManager.Coretype为'windowSizeChange'
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
......@@ -2388,8 +2571,9 @@ loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
windowStage.loadContent("pages/page2", (err, data) => {
......@@ -2397,11 +2581,11 @@ loadContent(path: string, callback: AsyncCallback&lt;void&gt;): void
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
}
}
```
}
```
### on('windowStageEvent')<sup>9+</sup>
......@@ -2409,6 +2593,8 @@ on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;
开启WindowStage生命周期变化的监听。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
......@@ -2416,21 +2602,21 @@ on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 是 | 回调返回监听到的信息。 |
| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 是 | 回调函数。返回当前的WindowStage生命周期状态。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var type = 'windowStageEvent';
windowStage.on(type, (data) => {
windowStage.on('windowStageEvent', (data) => {
console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + JSON.stringify(data));
});
}
}
```
}
```
### off('windowStageEvent')<sup>9+</sup>
......@@ -2438,6 +2624,8 @@ off(eventType: 'windowStageEvent', callback?: Callback&lt;WindowStageEventType&g
关闭WindowStage生命周期变化的监听。
此接口仅可在Stage模型下使用。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:**
......@@ -2445,16 +2633,17 @@ off(eventType: 'windowStageEvent', callback?: Callback&lt;WindowStageEventType&g
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'windowStageEvent',即WindowStage生命周期变化事件。 |
| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 否 | 回调返回监听到的信息。 |
| callback | Callback&lt;[WindowStageEventType](#windowstageeventtype9)&gt; | 否 | 回调函数。返回当前的WindowStage生命周期状态。 |
**示例:**
```ts
class myAbility extends Ability {
```ts
import Ability from '@ohos.application.Ability';
class myAbility extends Ability {
onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate');
var type = 'windowStageEvent';
windowStage.off(type);
}
windowStage.off('windowStageEvent');
}
```
\ No newline at end of file
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册