未验证 提交 32ee7ebd 编写于 作者: O openharmony_ci 提交者: Gitee

!15163 翻译完成:14779 master:window开发指南使用最新的接口

Merge pull request !15163 from wusongqing/TR14779
......@@ -21,7 +21,7 @@ The table below lists the common APIs used for application window development. F
| Instance| API| Description|
| -------- | -------- | -------- |
| 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&lt;Window&gt;): void | Finds a window based on the ID.|
| Window static method| findWindow(name: string): Window | Finds a window based on the name.|
| Window | SetUIContent(path: string, callback: AsyncCallback&lt;void&gt;): void | Loads the page content to this window.|
| Window | moveWindowTo(x: number, y: number, callback: AsyncCallback&lt;void&gt;): void | Moves this window.|
| Window | setWindowBackgroundColor(color: string, callback: AsyncCallback&lt;void&gt;): void | Sets the background color for this window.|
......@@ -62,14 +62,11 @@ You can create a subwindow, such as a dialog box, and set its properties.
windowClass = 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;
}
console.info('Succeeded in finding subWindow. Data: ' + JSON.stringify(data));
windowClass = data;
});
try {
windowClass = window.findWindow('subWindow');
} catch (exception) {
console.error('Failed to find the Window. Cause: ' + JSON.stringify(exception));
}
```
2. Set the properties of the subwindow.
......@@ -154,7 +151,7 @@ To create a better video watching and gaming experience, you can use the immersi
let mainWindowClass = null;
// Obtain the main window.
window.getLastWindow((err, data) => {
window.getLastWindow(this.context,(err, data) => {
if (err.code) {
console.error('Failed to get the subWindow. Cause: ' + JSON.stringify(err));
return;
......@@ -164,7 +161,7 @@ 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:
2. Implement the immersive effect. You can use either of the following methods:
- 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.
......
......@@ -49,7 +49,7 @@ The table below lists the common APIs used for application window development. F
## Setting the Main Window of an Application
In the stage model, the main window of an application is created and maintained by an **Ability** instance. In the **onWindowStageCreate** callback of the **Ability** instance, use **WindowStage** to obtain the main window of the application and set its properties.
In the stage model, the main window of an application is created and maintained by a **UIAbility** instance. In the **onWindowStageCreate** callback of the **UIAbility** instance, use **WindowStage** to obtain the main window of the application and set its properties. You can also set the properties (for example, **maxWindowWidth**) in the [module.json5 file](../quick-start/module-configuration-file.md#abilities).
### How to Develop
......@@ -66,41 +66,41 @@ In the stage model, the main window of an application is created and maintained
Call **loadContent** to load the page content to the main window.
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 1. Obtain the main window of the application.
let 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));
// 2. Set the touchable property of the main window.
let isTouchable = true;
windowClass.setWindowTouchable(isTouchable, (err) => {
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.');
})
})
// 3. Load the page content to the main window.
windowStage.loadContent("pages/page2", (err) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content.');
});
}
};
```
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 1. Obtain the main window of the application.
let 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));
// 2. Set the touchable property of the main window.
let isTouchable = true;
windowClass.setWindowTouchable(isTouchable, (err) => {
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.');
})
})
// 3. Load the page content to the main window.
windowStage.loadContent("pages/page2", (err) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content.');
});
}
};
```
## Setting a Subwindow of an Application
......@@ -211,7 +211,7 @@ To create a better video watching and gaming experience, you can use the immersi
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 either of the following methods:
- 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.
......@@ -282,7 +282,7 @@ To create a better video watching and gaming experience, you can use the immersi
## Setting a Floating Window
A floating window is created based on an existing task. It is always displayed in the foreground, even if the task used for creating the floating window is switched to the background. You can create a floating window and set its properties.
A floating window is created based on an existing task. It is always displayed in the foreground, even if the task used for creating the floating window is switched to the background. Generally, the floating window is above all application windows. You can create a floating window and set its properties.
### How to Develop
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册