Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
e239217b
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e239217b
编写于
6月 19, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
!19917 【轻量级 PR】:update zh-cn/application-dev/windowmanager/application-window-stage.md.
Merge pull request !19917 from 葛亚芳/N/A
上级
110772c9
05b329fa
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
228 addition
and
212 deletion
+228
-212
zh-cn/application-dev/windowmanager/application-window-stage.md
...application-dev/windowmanager/application-window-stage.md
+228
-212
未找到文件。
zh-cn/application-dev/windowmanager/application-window-stage.md
浏览文件 @
e239217b
...
...
@@ -30,7 +30,7 @@
上述场景涉及的常用接口如下表所示。更多API说明请参见
[
API参考
](
../reference/apis/js-apis-window.md
)
。
| 实例名 | 接口名 | 描述 |
| --------
| -------- |
-------- |
| --------
------ | ------------------------------------------------------------ | ----------------------------------------------------
-------- |
| WindowStage | getMainWindow(callback: AsyncCallback
<
Window
>
): void | 获取
`WindowStage`
实例下的主窗口。
<br/>
此接口仅可在
`Stage`
模型下使用。 |
| WindowStage | loadContent(path: string, callback: AsyncCallback
<
void
>
): void | 为当前
`WindowStage`
的主窗口加载具体页面。
<br/>
此接口仅可在
`Stage`
模型下使用。 |
| WindowStage | createSubWindow(name: string, callback: AsyncCallback
<
Window
>
): void | 创建子窗口。
<br/>
此接口仅可在
`Stage`
模型下使用。 |
...
...
@@ -57,12 +57,15 @@
### 开发步骤
1.
获取应用主窗口。
通过
`getMainWindow`
接口获取应用主窗口。
2.
设置主窗口属性。
可设置主窗口的背景色、亮度值、是否可触等多个属性,开发者可根据需要选择对应的接口。本示例以设置“是否可触”属性为例。
3.
为主窗口加载对应的目标页面。
通过
`loadContent`
接口加载主窗口的目标页面。
```
ts
...
...
@@ -101,7 +104,6 @@ export default class EntryAbility extends UIAbility {
};
```
## 设置应用子窗口
开发者可以按需创建应用子窗口,如弹窗等,并对其进行属性设置等操作。
...
...
@@ -110,23 +112,28 @@ export default class EntryAbility extends UIAbility {
### 开发步骤
1.
创建应用子窗口。
通过
`createSubWindow`
接口创建应用子窗口。
2.
设置子窗口属性。
子窗口创建成功后,可以改变其大小、位置等,还可以根据应用需要设置窗口背景色、亮度等属性。
3.
加载显示子窗口的具体内容。
通过
`setUIContent`
和
`showWindow`
接口加载显示子窗口的具体内容。
4.
销毁子窗口。
当不再需要某些子窗口时,可根据具体实现逻辑,使用
`destroyWindow`
接口销毁子窗口。
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
let
windowStage_
=
null
;
let
sub_windowClass
=
null
;
let
windowStage_
=
null
;
let
sub_windowClass
=
null
;
export
default
class
EntryAbility
extends
UIAbility
{
export
default
class
EntryAbility
extends
UIAbility
{
showSubWindow
()
{
// 1.创建应用子窗口。
windowStage_
.
createSubWindow
(
"
mySubWindow
"
,
(
err
,
data
)
=>
{
...
...
@@ -191,9 +198,8 @@ export default class EntryAbility extends UIAbility {
// 开发者可以在适当的时机,如子窗口上点击关闭按钮等,销毁子窗口。并不一定需要在onWindowStageDestroy调用,这里仅作展示
this
.
destroySubWindow
();
}
};
```
};
```
## 体验窗口沉浸式能力
...
...
@@ -203,19 +209,23 @@ export default class EntryAbility extends UIAbility {
### 开发步骤
1.
获取应用主窗口。
通过
`getMainWindow`
接口获取应用主窗口。
2.
实现沉浸式效果。有以下两种方式:
-
方式一:调用
`setWindowSystemBarEnable`
接口,设置导航栏、状态栏不显示,从而达到沉浸式效果。
-
方式二:调用
`setWindowLayoutFullScreen`
接口,设置应用主窗口为全屏布局;然后调用
`setWindowSystemBarProperties`
接口,设置导航栏、状态栏的透明度、背景/文字颜色以及高亮图标等属性,使之保持与主窗口显示协调一致,从而达到沉浸式效果。
3.
加载显示沉浸式窗口的具体内容。
通过
`loadContent`
接口加载沉浸式窗口的具体内容。
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
export
default
class
EntryAbility
extends
UIAbility
{
export
default
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
)
{
// 1.获取应用主窗口。
let
windowClass
=
null
;
...
...
@@ -269,9 +279,8 @@ export default class EntryAbility extends UIAbility {
console
.
info
(
'
Succeeded in loading the content.
'
);
});
}
};
```
};
```
## 设置悬浮窗
...
...
@@ -281,6 +290,7 @@ export default class EntryAbility extends UIAbility {
### 开发步骤
1.
申请权限。
创建
`WindowType.TYPE_FLOAT`
即悬浮窗类型的窗口,需要在
`module.json5`
文件的
`requestPermissions`
对象中配置
`ohos.permission.SYSTEM_FLOAT_WINDOW`
权限。更多配置信息详见
[
module.json5配置文件
](
../quick-start/module-configuration-file.md
)
。
> **说明:**
...
...
@@ -306,27 +316,32 @@ export default class EntryAbility extends UIAbility {
```
2.
创建悬浮窗。
通过
`window.createWindow`
接口创建悬浮窗类型的窗口。
3.
对悬浮窗进行属性设置等操作。
悬浮窗窗口创建成功后,可以改变其大小、位置等,还可以根据应用需要设置悬浮窗背景色、亮度等属性。
4.
加载显示悬浮窗的具体内容。
通过
`setUIContent`
和
`showWindow`
接口加载显示悬浮窗的具体内容。
5.
销毁悬浮窗。
当不再需要悬浮窗时,可根据具体实现逻辑,使用
`destroyWindow`
接口销毁悬浮窗。
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
window
from
'
@ohos.window
'
;
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
window
from
'
@ohos.window
'
;
export
default
class
EntryAbility
extends
UIAbility
{
export
default
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
)
{
// 2. 创建悬浮窗。
let
windowClass
=
null
;
let
config
=
{
name
:
"
floatWindow
"
,
windowType
:
window
.
WindowType
.
TYPE_FLOAT
,
ctx
:
this
.
context
};
let
config
=
{
name
:
"
floatWindow
"
,
windowType
:
window
.
WindowType
.
TYPE_FLOAT
,
ctx
:
this
.
context
};
window
.
createWindow
(
config
,
(
err
,
data
)
=>
{
if
(
err
.
code
)
{
console
.
error
(
'
Failed to create the floatWindow. Cause:
'
+
JSON
.
stringify
(
err
));
...
...
@@ -375,8 +390,9 @@ export default class EntryAbility extends UIAbility {
});
});
}
};
```
};
```
## 相关实例
针对window开发(Stage模型),有以下相关实例可供参考:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录