未验证 提交 88b31b61 编写于 作者: O openharmony_ci 提交者: Gitee

!9324 master :windowmanager-相关示例代码规范及说明优化修改:需同步翻译

Merge pull request !9324 from 葛亚芳/master
......@@ -55,7 +55,7 @@
```js
import window from '@ohos.window';
var windowClass = null;
let windowClass = null;
// 1.方式一:创建子窗口。
window.create("subWindow", window.WindowType.TYPE_APP, (err, data) => {
if (err.code) {
......@@ -162,13 +162,17 @@
1. 获取主窗口对象。
沉浸式能力需要在成功获取应用主窗口对象的前提下进行。使用`window.getTopWindow`接口来获取得到主窗口。
> **说明:**
>
> 沉浸式能力需要在成功获取应用主窗口对象的前提下进行。
>
> 确保应用内最后显示的窗口为主窗口,然后再使用`window.getTopWindow`接口来获取得到主窗口。
```js
import window from '@ohos.window';
var mainWindowClass = null;
let mainWindowClass = null;
// 1.获取主窗口
window.getTopWindow((err, data) => {
if (err.code) {
......@@ -188,7 +192,7 @@
```js
// 2.实现沉浸式效果。方式一:设置窗口全屏显示。
var isFullScreen = true;
let isFullScreen = true;
mainWindowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
......@@ -197,7 +201,7 @@
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});
// 2.实现沉浸式效果。方式二:设置导航栏、状态栏不显示。
var names = [];
let names = [];
mainWindowClass.setSystemBarEnable(names, (err, data) => {
if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
......@@ -207,7 +211,7 @@
});
// 2.实现沉浸式效果。
// 方式三:设置窗口为全屏布局,配合设置状态栏、导航栏的透明度、背景/文字颜色及高亮图标等属性,与主窗口显示保持协调一致。
var isLayoutFullScreen = true;
let isLayoutFullScreen = true;
mainWindowClass.setLayoutFullScreen(isLayoutFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
......@@ -215,7 +219,7 @@
}
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
});
var SystemBarProperties = {
let sysBarProps = {
statusBarColor: '#ff00ff',
navigationBarColor: '#00ff00',
// 以下两个属性从API Version7开始支持
......@@ -225,7 +229,7 @@
statusBarContentColor: '#ffffff',
navigationBarContentColor: '#ffffff'
};
mainWindowClass.setSystemBarProperties(SystemBarProperties, (err, data) => {
mainWindowClass.setSystemBarProperties(sysBarProps, (err, data) => {
if (err.code) {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return;
......
......@@ -73,7 +73,7 @@ import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// 1.获取应用主窗口。
var windowClass = null;
let windowClass = null;
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
......@@ -82,7 +82,7 @@ class MainAbility extends Ability {
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// 2.设置主窗口属性。以设置"是否可触"属性为例。
var isTouchable = true;
let isTouchable = true;
windowClass.setTouchable(isTouchable, (err, data) => {
if (err.code) {
console.error('Failed to set the window to be touchable. Cause:' + JSON.stringify(err));
......@@ -132,7 +132,7 @@ class MainAbility extends Ability {
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// 1.创建应用子窗口。
var sub_windowClass = null;
let sub_windowClass = null;
windowStage.createSubWindow("mySubWindow", (err, data) => {
if (err.code) {
console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
......@@ -222,7 +222,7 @@ class MainAbility extends Ability {
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// 1.获取应用主窗口。
var windowClass = null;
let windowClass = null;
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
......@@ -232,7 +232,7 @@ class MainAbility extends Ability {
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// 2.实现沉浸式效果。方式一:设置应用主窗口为全屏显示。
var isFullScreen = true;
let isFullScreen = true;
windowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
......@@ -241,7 +241,7 @@ class MainAbility extends Ability {
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});
// 2.实现沉浸式效果。方式二:设置导航栏、状态栏不显示。
var names = [];
let names = [];
windowClass.setSystemBarEnable(names, (err, data) => {
if (err.code) {
console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
......@@ -250,7 +250,7 @@ class MainAbility extends Ability {
console.info('Succeeded in setting the system bar to be visible. Data: ' + JSON.stringify(data));
});
// 2.实现沉浸式效果。方式三:设置窗口为全屏布局,配合设置导航栏、状态栏的透明度、背景/文字颜色及高亮图标等属性,与主窗口显示保持协调一致。
var isLayoutFullScreen = true;
let 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));
......@@ -258,7 +258,7 @@ class MainAbility extends Ability {
}
console.info('Succeeded in setting the window layout to full-screen mode. Data: ' + JSON.stringify(data));
});
var SystemBarProperties = {
let sysBarProps = {
statusBarColor: '#ff00ff',
navigationBarColor: '#00ff00',
// 以下两个属性从API Version 7开始支持
......@@ -268,7 +268,7 @@ class MainAbility extends Ability {
statusBarContentColor: '#ffffff',
navigationBarContentColor: '#ffffff'
};
windowClass.setSystemBarProperties(SystemBarProperties, (err, data) => {
windowClass.setSystemBarProperties(sysBarProps, (err, data) => {
if (err.code) {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return;
......@@ -350,7 +350,7 @@ class MainAbility extends Ability {
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// 2. 创建悬浮窗。
var windowClass = null;
let windowClass = null;
window.create(this.context, "floatWindow", window.WindowType.TYPE_FLOAT, (err, data) => {
if (err.code) {
console.error('Failed to create the floatWindow. Cause: ' + JSON.stringify(err));
......
......@@ -16,7 +16,7 @@
import screenshot from '@ohos.screenshot' // 导入模块
// 设置屏幕截图参数
var ScreenshotOptions = {
let screenshotOps = {
"screenRect": {
"left": 200,
"top": 100,
......@@ -28,8 +28,7 @@ var ScreenshotOptions = {
"rotation": 0
};
let image; // image用来保存屏幕截图
screenshot.save(ScreenshotOptions).then((image) => {
screenshot.save(screenshotOps).then((image) => {
console.log('screenshot.save success, screenshot image :' + JSON.stringify(image));
}, (err) => {
console.log('screenshot.save failed, error : ' + JSON.stringify(err));
......
......@@ -47,14 +47,12 @@
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
import window from '@ohos.window';
var windowClass = null;
export default class ServiceExtensionAbility1 extends ExtensionContext {
onCreate(want) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
// 1.创建音量条窗口。
var windowClass = null;
let windowClass = null;
window.create(this.context, "volume", window.WindowType.TYPE_VOLUME_OVERLAY, (err, data) => {
if (err.code) {
console.error('Failed to create the volume window. Cause:' + JSON.stringify(err));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册