@@ -57,8 +57,9 @@ In the stage model, the main window of an application is created and maintained
...
@@ -57,8 +57,9 @@ In the stage model, the main window of an application is created and maintained
1. Obtain the main window.
1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application.
Call **getMainWindow** to obtain the main window of the application.
2. Set the properties of the main window.
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.
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.
...
@@ -83,21 +84,21 @@ class MainAbility extends Ability {
...
@@ -83,21 +84,21 @@ class MainAbility extends Ability {
console.info('Succeeded in obtaining the main window. Data: '+JSON.stringify(data));
console.info('Succeeded in obtaining the main window. Data: '+JSON.stringify(data));
// 2. Set the touchable property of the main window.
// 2. Set the touchable property of the main window.
console.error('Failed to load the content. Cause:'+JSON.stringify(err));
console.error('Failed to load the content. Cause:'+JSON.stringify(err));
return;
return;
}
}
console.info('Succeeded in loading the content. Data: '+JSON.stringify(data));
console.info('Succeeded in loading the content.');
// 3. Show the subwindow.
// 3. Show the subwindow.
sub_windowClass.show((err,data)=>{
sub_windowClass.show((err)=>{
if(err.code){
if(err.code){
console.error('Failed to show the window. Cause:'+JSON.stringify(err));
console.error('Failed to show the window. Cause:'+JSON.stringify(err));
return;
return;
}
}
console.info('Succeeded in showing the window. Data: '+JSON.stringify(data));
console.info('Succeeded in showing the window.');
});
});
});
});
})
})
...
@@ -189,18 +180,18 @@ Call **getSubWindow** to obtain a subwindow.
...
@@ -189,18 +180,18 @@ Call **getSubWindow** to obtain a subwindow.
destroySubWindow(){
destroySubWindow(){
// 4. Destroy the subwindow when it is no longer needed (depending on the service logic).
// 4. Destroy the subwindow when it is no longer needed (depending on the service logic).
sub_windowClass.destroy((err,data)=>{
sub_windowClass.destroy((err)=>{
if(err.code){
if(err.code){
console.error('Failed to destroy the window. Cause: '+JSON.stringify(err));
console.error('Failed to destroy the window. Cause: '+JSON.stringify(err));
return;
return;
}
}
console.info('Succeeded in destroying the window. Data: '+JSON.stringify(data));
console.info('Succeeded in destroying the window.');
});
});
}
}
onWindowStageCreate(windowStage){
onWindowStageCreate(windowStage){
windowStage_=windowStage;
windowStage_=windowStage;
// Create the subwindow when it is needed, for example, when a click event occurs in the main window. Calling onWindowStageCreate is not always necessary. The code here is for reference only.
// Create a subwindow when it is needed, for example, when a click event occurs in the main window. Calling onWindowStageCreate is not always necessary. The code here is for reference only.
this.showSubWindow();
this.showSubWindow();
}
}
...
@@ -221,8 +212,9 @@ To create a better video watching and gaming experience, you can use the immersi
...
@@ -221,8 +212,9 @@ To create a better video watching and gaming experience, you can use the immersi
1. Obtain the main window.
1. Obtain the main window.
Call **getMainWindow** to obtain the main window of the application.
Call **getMainWindow** to obtain the main window of the application.
2. Implement the immersive effect. You can use any of the following methods:
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 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 2: Call **setSystemBarEnable** to hide the navigation bar and status bar.
...
@@ -249,30 +241,30 @@ Call **getMainWindow** to obtain the main window of the application.
...
@@ -249,30 +241,30 @@ Call **getMainWindow** to obtain the main window of the application.
// 2. Use method 1 to implement the immersive effect.
// 2. Use method 1 to implement the immersive effect.
console.error('Failed to load the content. Cause:'+JSON.stringify(err));
console.error('Failed to load the content. Cause:'+JSON.stringify(err));
return;
return;
}
}
console.info('Succeeded in loading the content. Data: '+JSON.stringify(data));
console.info('Succeeded in loading the content.');
});
});
}
}
};
};
...
@@ -310,13 +302,13 @@ A floating window is created based on an existing task. It is always displayed i
...
@@ -310,13 +302,13 @@ A floating window is created based on an existing task. It is always displayed i
### How to Develop
### How to Develop
1. Apply for permissions.
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 details about the file, see [Application Package Structure Configuration File](../quick-start/stage-structure.md).
> **NOTE**
> **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).
> 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
```json
{
{
"module":{
"module":{
...
@@ -334,7 +326,7 @@ To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must co
...
@@ -334,7 +326,7 @@ To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must co
}
}
}
}
```
```
2. Create a floating window.
2. Create a floating window.
Call **window.create** to create a floating window.
Call **window.create** to create a floating window.
...
@@ -368,43 +360,43 @@ To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must co
...
@@ -368,43 +360,43 @@ To create a floating window (of the **WindowType.TYPE_FLOAT** type), you must co
console.info('Succeeded in creating the floatWindow. Data: '+JSON.stringify(data));
console.info('Succeeded in creating the floatWindow. Data: '+JSON.stringify(data));
windowClass=data;
windowClass=data;
// 3. Set the position, size, and properties of the floating window.
// 3. Set the position, size, and properties of the floating window.
windowClass.moveTo(300,300,(err,data)=>{
windowClass.moveTo(300,300,(err)=>{
if(err.code){
if(err.code){
console.error('Failed to move the window. Cause:'+JSON.stringify(err));
console.error('Failed to move the window. Cause:'+JSON.stringify(err));
return;
return;
}
}
console.info('Succeeded in moving the window. Data: '+JSON.stringify(data));
console.info('Succeeded in moving the window.');
});
});
windowClass.resetSize(500,1000,(err,data)=>{
windowClass.resetSize(500,1000,(err)=>{
if(err.code){
if(err.code){
console.error('Failed to change the window size. Cause:'+JSON.stringify(err));
console.error('Failed to change the window size. Cause:'+JSON.stringify(err));
return;
return;
}
}
console.info('Succeeded in changing the window size. Data: '+JSON.stringify(data));
console.info('Succeeded in changing the window size.');
});
});
// 4. Load the page content to the floating window.
// 4. Load the page content to the floating window.