未验证 提交 7a3def87 编写于 作者: O openharmony_ci 提交者: Gitee

!15165 翻译完成:14314 3.2Beta5:window开发指南使用最新的接口

Merge pull request !15165 from wusongqing/TR14314
......@@ -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.
### 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 Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
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
......@@ -127,11 +127,11 @@ You can create an application subwindow, such as a dialog box, and set its prope
When the subwindow is no longer needed, you can call **destroyWindow** to destroy it.
```ts
import Ability from '@ohos.application.Ability'
import UIAbility from '@ohos.app.ability.UIAbility';
let windowStage_ = null;
let sub_windowClass = null;
class MainAbility extends Ability {
export default class EntryAbility extends UIAbility {
showSubWindow() {
// 1. Create a subwindow.
windowStage_.createSubWindow("mySubWindow", (err, data) => {
......@@ -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.
......@@ -220,9 +220,9 @@ To create a better video watching and gaming experience, you can use the immersi
Call **loadContent** to load the content to the immersive window.
```ts
import Ability from '@ohos.application.Ability'
import UIAbility from '@ohos.app.ability.UIAbility';
class MainAbility extends Ability {
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 1. Obtain the main window of the application.
let windowClass = null;
......@@ -303,7 +303,7 @@ A floating window is created based on an existing task. It is always displayed i
"name" : "ohos.permission.SYSTEM_FLOAT_WINDOW",
"usedScene": {
"abilities": [
"MainAbility"
"EntryAbility"
],
"when":"inuse"
}
......@@ -330,11 +330,11 @@ A floating window is created based on an existing task. It is always displayed i
When the floating window is no longer needed, you can call **destroyWindow** to destroy it.
```ts
import Ability from '@ohos.application.Ability'
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import ExtensionContext from '@ohos.app.ability.ServiceExtensionAbility';
import window from '@ohos.window';
class MainAbility extends Ability {
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 2. Create a floating window.
let windowClass = null;
......
......@@ -58,12 +58,11 @@ This section uses the volume bar as an example to describe how to develop a syst
When the volume bar window is no longer needed, you can call **hide** or **destroyWindow** to hide or destroy it.
```ts
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
import ExtensionContext from '@ohos.app.ability.ServiceExtensionAbility';
import window from '@ohos.window';
export default class ServiceExtensionAbility1 extends ExtensionContext {
onCreate(want) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
// 1. Create a volume bar window.
let windowClass = null;
......@@ -151,7 +150,6 @@ import window from '@ohos.window';
export default class ServiceExtensionAbility1 extends ExtensionContext {
onCreate(want) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
// Create a volume bar window.
let windowClass = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册