The **Window** module provides basic window management capabilities, such as creating and destroying the current window, setting properties for the current window, and managing and scheduling windows.
...
...
@@ -46,17 +46,15 @@ Enumerates the window types.
## Configuration<sup>9+</sup>
Defines the parameters used for creating a subwindow.
An asynchronous callback is used when a system window is created in the case that [ServiceExtensionContext](js-apis-service-extension-context.md) is used as the context.
Defines the parameters for creating a subwindow or system window.
| windowType | [WindowType](#windowtype7) | Yes| Type of the subwindow. |
| ctx | BaseContext | No| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-service-extension-context.md).<br> If this parameter is not set, no context is used. |
| name | string | Yes| Name of the window. |
| windowType | [WindowType](#windowtype7) | Yes| Type of the window. |
| ctx | BaseContext | No| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md). If this parameter is not set, no context is used.<br>A system window is created when **Context** is [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md).|
| displayId | number | No| ID of the current physical screen. If this parameter is not set, the default value **-1** is used.|
| parentId | number | No| ID of the parent window. If this parameter is not set, the default value **-1** is used. |
...
...
@@ -302,7 +300,7 @@ Describes the translation parameters.
| ctx | BaseContext | Yes| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| ctx | BaseContext | Yes| Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback<[Window](#window)> | Yes| Callback used to return the top window obtained.|
**Error codes**
...
...
@@ -474,7 +472,7 @@ Obtains the top window of the current application. This API uses a promise to re
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-service-extension-context.md).|
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md).|
| id | string | Yes | Window ID. |
| type | [WindowType](#windowtype7) | Yes | Window type. |
| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the subwindow created. |
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-service-extension-context.md).|
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md).|
| id | string | Yes | Window ID. |
| type | [WindowType](#windowtype7) | Yes | Window type. |
...
...
@@ -1123,7 +1121,7 @@ Obtains the top window of the current application. This API uses an asynchronous
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback<[Window](#window)> | Yes | Callback used to return the top window obtained. |
**Example**
...
...
@@ -1156,7 +1154,7 @@ Obtains the top window of the current application. This API uses a promise to re
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-Context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
| ctx | BaseContext | Yes | Current application context.<br>For details about the context in the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the context in the stage model, see [Context](js-apis-ability-context.md).|
**Return value**
...
...
@@ -1983,7 +1981,7 @@ Sets whether to display the status bar and navigation bar in this window. This A
| names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.|
| names | Array<'status'\|'navigation'> | Yes| Whether to display the status bar and navigation bar.<br>For example, to display the status bar and navigation bar, set this parameter to **['status', 'navigation']**. By default, they are not displayed.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
@@ -20,21 +20,19 @@ The table below lists the common APIs used for application window development. F
| Instance| API| Description|
| -------- | -------- | -------- |
| Window static method| create(id: string, type: WindowType, callback: AsyncCallback<Window>): void | Creates a subwindow.<br>This API can be used only in the FA model.|
| Window static method| getTopWindow(callback: AsyncCallback<Window>): void | Obtains the top window of the current application.<br>This API can be used only in the FA model.|
| Window static method| find(id: string, callback: AsyncCallback<Window>): void | Finds a window based on the ID.|
| Window | loadContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window.|
| Window | setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for this window.|
| Window | setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for the window layout. |
| Window | setSystemBarEnable(names: Array<'status'\|'navigation'>): Promise<void> | Sets whether to display the status bar and navigation bar in this window.|
| Window | setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | show(callback: AsyncCallback\<void>): void | Shows this window.|
| Window static method| createWindow(config: Configuration, callback: AsyncCallback\<Window>): void | Creates a subwindow.<br>**config** specifies the parameters used for creating the window.|
| Window static method| findWindow(id: string, callback: AsyncCallback<Window>): void | Finds a window based on the ID.|
| Window | SetUIContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window.|
| Window | setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for the window layout. |
| Window | setWindowSystemBarEnable(names: Array<'status'\|'navigation'>): Promise<void> | Sets whether to display the status bar and navigation bar in this window.|
| Window | setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | showWindow(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | on(type: 'touchOutside', callback: Callback<void>): void | Enables listening for click events outside this window.|
| Window | destroy(callback: AsyncCallback<void>): void | Destroys this window.|
| Window | destroyWindow(callback: AsyncCallback<void>): void | Destroys this window.|
## Setting the Subwindow of an Application
...
...
@@ -46,16 +44,16 @@ You can create a subwindow, such as a dialog box, and set its properties.
1. Create or obtain a subwindow.
- Call **window.create** to create a subwindow.
- Call **window.getTopWindow** to obtain the top window – subwindow.
- Call **window.find** to find an available subwindow.
```js
- Call **window.createWindow** to create a subwindow.
- Call **window.findWindow** to find an available subwindow.
console.error('Failed to create the subWindow. Cause: '+JSON.stringify(err));
return;
...
...
@@ -63,17 +61,8 @@ You can create a subwindow, such as a dialog box, and set its properties.
console.info('Succeeded in creating subWindow. Data: '+JSON.stringify(data));
windowClass=data;
});
// Method 2: Obtain a subwindow.
window.getTopWindow((err,data)=>{
if(err.code){
console.error('Failed to get the subWindow. Cause: '+JSON.stringify(err));
return;
}
console.info('Succeeded in getting subWindow. Data: '+JSON.stringify(data));
windowClass=data;
});
// Method 3: Find a subwindow.
window.find("subWindow",(err,data)=>{
// Method 2: Find a subwindow.
window.findWindow("subWindow",(err,data)=>{
if(err.code){
console.error('Failed to find the subWindow. Cause: '+JSON.stringify(err));
return;
...
...
@@ -81,15 +70,15 @@ You can create a subwindow, such as a dialog box, and set its properties.
console.info('Succeeded in finding subWindow. Data: '+JSON.stringify(data));
windowClass=data;
});
```
```
2. Set the properties of the subwindow.
After the subwindow is created, you can set its properties, such as the size, position, background color, and brightness.
```js
// Move the subwindow.
windowClass.moveTo(300,300,(err)=>{
windowClass.moveWindowTo(300,300,(err)=>{
if(err.code){
console.error('Failed to move the window. Cause:'+JSON.stringify(err));
return;
...
...
@@ -97,7 +86,7 @@ You can create a subwindow, such as a dialog box, and set its properties.
console.info('Succeeded in moving the window.');
});
// Change the size of the subwindow.
windowClass.resetSize(500,1000,(err)=>{
windowClass.resize(500,500,(err)=>{
if(err.code){
console.error('Failed to change the window size. Cause:'+JSON.stringify(err));
return;
...
...
@@ -108,18 +97,18 @@ You can create a subwindow, such as a dialog box, and set its properties.
3. Load content for the subwindow and show it.
Call **loadContent** and **show** to load and display the content in the subwindow.
Call **SetUIContent** and **showWindow** to load and display the content in the subwindow.
```js
// Load the page content to the subwindow.
windowClass.loadContent("pages/page2",(err)=>{
windowClass.SetUIContent("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.');
// Show the subwindow.
windowClass.show((err)=>{
windowClass.showWindow((err)=>{
if(err.code){
console.error('Failed to show the window. Cause: '+JSON.stringify(err));
return;
...
...
@@ -131,11 +120,11 @@ You can create a subwindow, such as a dialog box, and set its properties.
4. Destroy the subwindow.
When the subwindow is no longer needed, you can call **destroy()** to destroy it.
When the subwindow is no longer needed, you can call **destroyWindow** to destroy it.
```js
// Call destroy() to destroy the subwindow when it is no longer needed.
windowClass.destroy((err)=>{
windowClass.destroyWindow((err)=>{
if(err.code){
console.error('Failed to destroy the subwindow. Cause:'+JSON.stringify(err));
return;
...
...
@@ -158,14 +147,14 @@ To create a better video watching and gaming experience, you can use the immersi
>
> The immersive window feature can be implemented only after the main window is obtained.
>
> Ensure that the top window of the application is the main window. You can use **window.getTopWindow** to obtain the main window.
> Ensure that the top window of the application is the main window. You can use **window.getLastWindow** to obtain the main window.
```js
importwindowfrom'@ohos.window';
letmainWindowClass=null;
// Obtain the main window.
window.getTopWindow((err,data)=>{
window.getLastWindow((err,data)=>{
if(err.code){
console.error('Failed to get the subWindow. Cause: '+JSON.stringify(err));
return;
...
...
@@ -177,32 +166,23 @@ To create a better video watching and gaming experience, you can use the immersi
2. Implement the immersive effect. You can use any of the following methods:
- Method 1: Call **setFullScreen** to set the main window to be displayed in full screen. In this case, the navigation bar and status bar are hidden.
- Method 2: Call **setSystemBarEnable** to hide the navigation bar and status bar.
- Method 3: Call **setLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setSystemProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
- Method 1: Call **setWindowSystemBarEnable** to hide the navigation bar and status bar.
- Method 2: Call **setWindowLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setSystemProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
```js
// Use method 1 to implement the immersive effect.
@@ -32,20 +32,19 @@ The table below lists the common APIs used for application window development. F
| WindowStage | getMainWindow(callback: AsyncCallback<Window>): void | Obtains the main window of this window stage.<br>This API can be used only in the stage model.|
| WindowStage | loadContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to the main window in this window stage.<br>This API can be used only in the stage model.|
| WindowStage | createSubWindow(name: string, callback: AsyncCallback<Window>): void | Creates a subwindow.<br>This API can be used only in the stage model.|
| Window | setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for this window.|
| Window | setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for the window layout. |
| Window | setSystemBarEnable(names: Array<'status'\|'navigation'>): Promise<void> | Sets whether to display the status bar and navigation bar in this window.|
| Window | setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | show(callback: AsyncCallback\<void>): void | Shows this window.|
| Window static method| createWindow(config: Configuration, callback: AsyncCallback\<Window>): void | Creates a system window.<br>**config** specifies the parameters used for creating the window.|
| Window | setUIContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window.|
| Window | setWindowBackgroundColor(color: string, callback: AsyncCallback<void>): void | Sets the background color for this window.|
| Window | setWindowBrightness(brightness: number, callback: AsyncCallback<void>): void | Sets the brightness for this window.|
| Window | setWindowTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void | Sets whether this window is touchable.|
| Window | setWindowLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void | Sets whether to enable the full-screen mode for the window layout. |
| Window | setWindowSystemBarEnable(names: Array<'status'\|'navigation'>): Promise<void> | Sets whether to display the status bar and navigation bar in this window.|
| Window | setWindowSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void | Sets the properties of the status bar and navigation bar in this window.<br>**systemBarProperties**: properties of the status bar and navigation bar.|
| Window | showWindow(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | on(type: 'touchOutside', callback: Callback<void>): void | Enables listening for click events outside this window.|
| Window | destroy(callback: AsyncCallback<void>): void | Destroys this window.|
| Window | destroyWindow(callback: AsyncCallback<void>): void | Destroys this window.|
## Setting the Main Window of an Application
...
...
@@ -56,16 +55,12 @@ In the stage model, the main window of an application is created and maintained
### How to Develop
1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application.
2. Set the properties of the main window.
You can set multiple properties of the main window, such as the background color, brightness, and whether the main window is touchable. The code snippet below uses the **touchable** property as an example.
3. Load content for the main window.
Call **loadContent** to load the page content to the main window.
```ts
...
...
@@ -84,7 +79,7 @@ class MainAbility extends Ability {
console.info('Succeeded in obtaining the main window. Data: '+JSON.stringify(data));
// 2. Set the touchable property of the main window.
console.error('Failed to load the content. Cause:'+JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content.');
// 3. Show the subwindow.
sub_windowClass.show((err)=>{
sub_windowClass.showWindow((err)=>{
if(err.code){
console.error('Failed to show the window. Cause: '+JSON.stringify(err));
return;
...
...
@@ -180,7 +170,7 @@ You can create an application subwindow, such as a dialog box, and set its prope
destroySubWindow(){
// 4. Destroy the subwindow when it is no longer needed (depending on the service logic).
sub_windowClass.destroy((err)=>{
sub_windowClass.destroyWindow((err)=>{
if(err.code){
console.error('Failed to destroy the window. Cause: '+JSON.stringify(err));
return;
...
...
@@ -211,19 +201,15 @@ To create a better video watching and gaming experience, you can use the immersi
### How to Develop
1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application.
2. Implement the immersive effect. You can use any of the following methods:
- Method 1: Call **setFullScreen** to set the main window to be displayed in full screen. In this case, the navigation bar and status bar are hidden.
- Method 2: Call **setSystemBarEnable** to hide the navigation bar and status bar.
- Method 3: Call **setLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setSystemProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
- Method 1: Call **setWindowSystemBarEnable** to hide the navigation bar and status bar.
- Method 2: Call **setWindowLayoutFullScreen** to enable the full-screen mode for the main window layout. Call **setWindowSystemBarProperties** to set the opacity, background color, text color, and highlighted icon of the navigation bar and status bar to ensure that their display effect is consistent with that of the main window.
3. Load content for the immersive window and show it.
Call **loadContent** to load the content to the immersive window.
```ts
importAbilityfrom'@ohos.application.Ability'
...
...
@@ -240,26 +226,17 @@ To create a better video watching and gaming experience, you can use the immersi
console.info('Succeeded in obtaining the main window. Data: '+JSON.stringify(data));
// 2. Use method 1 to implement the immersive effect.
letisFullScreen=true;
windowClass.setFullScreen(isFullScreen,(err)=>{
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.');
});
// 2. Use method 2 to implement the immersive effect.
console.error('Failed to set the system bar properties. Cause: '+JSON.stringify(err));
return;
...
...
@@ -302,13 +279,12 @@ A floating window is created based on an existing task. It is always displayed i
### How to Develop
1. Apply for permissions.
To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For details about the file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md).
To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must configure the **ohos.permission.SYSTEM_FLOAT_WINDOW** permission in the **requestPermissions** field of the **module.json5** file. For more configuration information, see [module.json5 Configuration File](../quick-start/module-configuration-file.md).
> **NOTE**
>
> If the task for creating the floating window is reclaimed by the system, the floating window will no longer be displayed. If you want the floating window to be displayed in such a case, apply for a [continuous task](../task-management/background-task-overview.md).
```json
{
"module":{
...
...
@@ -324,24 +300,21 @@ A floating window is created based on an existing task. It is always displayed i
}
]
}
}
}
```
2. Create a floating window.
Call **window.create** to create a floating window.
Call **window.createWindow** to create a floating window.
3. Set properties for the floating window.
After the floating window is created, you can set its properties, such as the size, position, background color, and brightness.
4. Load content for the floating window and show it.
Call **loadContent** and **show** to load and display the content in the floating window.
Call **setUIContent** and **showWindow** to load and display the content in the floating window.
5. Destroy the floating window.
When the floating window is no longer needed, you can call **destroy** to destroy it.
When the floating window is no longer needed, you can call **destroyWindow** to destroy it.
```ts
importAbilityfrom'@ohos.application.Ability'
...
...
@@ -352,7 +325,8 @@ A floating window is created based on an existing task. It is always displayed i
| Window | loadContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window.|
| Window | show(callback: AsyncCallback\<void>): void | Shows this window.|
| Window static method| createWindow(config: Configuration, callback: AsyncCallback\<Window>): void | Creates a subwindow or system window.<br>**config** specifies the parameters used for creating the window.|
| Window | SetUIContent(path: string, callback: AsyncCallback<void>): void | Loads the page content to this window.|
| Window | showWindow(callback: AsyncCallback\<void>): void | Shows this window.|
| Window | on(type: 'touchOutside', callback: Callback<void>): void | Enables listening for click events outside this window.|
| Window | hide (callback: AsyncCallback\<void>): void | Hides this window. This is a system API.|
| Window | destroy(callback: AsyncCallback<void>): void | Destroys this window.|
| Window | destroyWindow(callback: AsyncCallback<void>): void | Destroys this window.|
## How to Develop
...
...
@@ -33,7 +33,7 @@ This section uses the volume bar as an example to describe the steps for system
1. Create a system window.
In the case of [ServiceExtensionContext](../reference/apis/js-apis-service-extension-context.md), call **window.create** to create a system window of the volume bar type.
In the case of [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md), call **window.createWindow** to create a system window of the volume bar type.
2. Set the properties of the system window.
...
...
@@ -41,11 +41,11 @@ This section uses the volume bar as an example to describe the steps for system
3. Load content for the system window and show it.
You can call **loadContent** and **show** to load and display the content in the volume bar window.
You can call **SetUIContent** and **showWindow** to load and display the content in the volume bar window.
4. Hide or destroy the system window.
When the volume bar window is no longer needed, you can call **hide** or **destroy** to hide or destroy it.
When the volume bar window is no longer needed, you can call **hide** or **destroyWindow** to hide or destroy it.