在 OpenHarmony(ArkUI,eTag/Stage 模型) 中,“菜单全屏”通常有两种理解,下面分别说明:
适用于 Stage 模型。
import window from '@ohos.window';
@Entry
@Component
struct Index {
aboutToAppear() {
window.getLastWindow(getContext(this), (err, win) => {
if (!err) {
// 隐藏状态栏和导航栏
win.setWindowLayoutFullScreen(true);
win.setWindowSystemBarEnable(['status', 'navigation']);
}
});
}
build() {
Column() {
// 页面内容
}
.width('100%')
.height('100%')
}
}
✅ 效果:页面真正铺满整个屏幕
"abilities": [
{
"name": "EntryAbility",
"window": {
"fullScreen": true
}
}
]
⚠️ 仅部分版本支持,建议配合 Window API 使用
OpenHarmony 的 Menu 默认是 弹出式菜单,不是全屏控件,但你可以:
@Entry
@Component
struct Index {
@State showMenu: boolean = false
build() {
Stack() {
Button('打开菜单')
.onClick(() => this.showMenu = true)
if (this.showMenu) {
Column() {
Text('菜单项1').fontSize(20)
Text('菜单项2').fontSize(20)
Text('菜单项3').fontSize(20)
}
.width('100%')
.height('100%')
.backgroundColor('#ffffff')
.onClick(() => this.showMenu = false)
}
}
.width('100%')
.height('100%')
}
}
✅ 本质是“全屏覆盖层”,常用于设置页、抽屉菜单
Navigation() {
// 全屏菜单页
}
.mode(NavigationMode.Stack)
适合 多页面菜单结构
| 误区 | 说明 |
|---|---|
| Menu 能直接全屏 | ❌ 不支持 |
| 只设 width 100% | ❌ 仍有状态栏 |
| 隐藏导航栏影响返回 | ✅ 需自行处理 |
window.setWindowLayoutFullScreen(true)Stack / Column 覆盖层Navigation / Router如果你能说明:
我可以给你更精确的示例代码。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。