鸿蒙设置沉浸式状态栏、全屏、获取导航栏高度
创始人
2024-11-11 22:40:50
0

场景1.在EntryAbility.ts中设置

  onWindowStageCreate(windowStage: window.WindowStage) {       let windowClass: window.Window = null;     windowStage.getMainWindow((err, data) => {       // 1.获取应用主窗口       windowClass = data;       // 2.设置导航栏、状态栏不显示。       windowClass.setWindowSystemBarEnable([], (err) => {        });       // 3.设置全屏       windowClass.setWindowLayoutFullScreen(true).then(() => {        })       // 4.获取底部导航栏高度,此时的高度单位是px       let navigationHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).bottomRect.height       PersistentStorage.PersistProps([{         key: "navigationHeight", defaultValue: navigationHeight       }])       windowStage.loadContent('pages/Index', (err, data) => {        });     })    }

此时APP顶部状态栏和底部导航栏都将被隐藏,并且页面全面屏显示

场景2. 如果想要在其他页面继续显示状态栏和底部导航栏又该怎么做呢?

第一步:先获取context属性

导入依赖

import common from '@ohos.app.ability.common' import window from '@ohos.window'

声明context属性

private context = getContext(this) as common.UIAbilityContext
aboutToAppear()方法中
aboutToAppear() {   window.getLastWindow(this.context).then((windowClass) => {     windowClass.setWindowSystemBarEnable(["status", "navigation"]).then(() => {     })   }) }

"status"和"navigation"就对象状态栏和导航栏。想显示哪个就写哪个

如果想获取导航栏的高度为vp,那么通过下面方法获取

px2vp(this.navigationHeight)

注意:目前我只在页面中能获取到px2vp这个方法,在ability中我没有获取到。如果有更好的方法麻烦告诉我一下

相关内容

热门资讯

一分钟脚本!werplan怎么... 一分钟脚本!werplan怎么透视(透视)外挂透明挂辅助app(2025新版技巧)-哔哩哔哩1、首先...
十分钟普及!福建大菠萝万能辅助... 十分钟普及!福建大菠萝万能辅助器(原来真的有挂)详细教程(有挂技巧)-哔哩哔哩;1)福建大菠萝万能辅...
8分钟科研!we-poker软... 8分钟科研!we-poker软件(透视)外挂透明挂辅助挂(科技教程)-哔哩哔哩;we-poker软件...
两分钟技巧!德州局HHpoke... 两分钟技巧!德州局HHpoker透视脚本(好像真的有挂)详细教程(有挂脚本)-哔哩哔哩;1、让任何用...
7分钟规律!wepokre俱乐... 7分钟规律!wepokre俱乐部辅助(辅助挂)透视脚本辅助挂(2025新版)-哔哩哔哩;1、点击下载...
三分钟发现!wepoker透视... 三分钟发现!wepoker透视脚本免费app(一贯真的有挂)详细教程(有挂攻略)-哔哩哔哩1、上手简...
2分钟曝光!wepoker私人... 2分钟曝光!wepoker私人局辅助器怎么用(辅助)外挂透明挂辅助神器(曝光教程)-哔哩哔哩1、we...
两分钟科普!购买wepoker... 两分钟科普!购买wepoker模拟器(一般真的有挂)详细教程(有挂方法)-哔哩哔哩1、首先打开购买w...
7分钟实锤!poker wor... 7分钟实锤!poker world辅助(辅助)外挂透明挂辅助工具(2025新版)-哔哩哔哩暗藏猫腻,...
九分钟揭秘!werplan脚本... 九分钟揭秘!werplan脚本(总是真的有挂)详细教程(有挂方法)-哔哩哔哩1、在werplan脚本...