欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > 鸿蒙 沉浸式状态栏键盘相关

鸿蒙 沉浸式状态栏键盘相关

2025/6/18 10:34:26 来源:https://blog.csdn.net/FlyPig_Vip/article/details/148682298  浏览:    关键词:鸿蒙 沉浸式状态栏键盘相关

设置全局的沉浸式状态栏

在Ability 设置

onWindowStageCreate(windowStage: window.WindowStage): void {// Main window is created, set main page for this abilityhilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');windowStage.loadContent('pages/Index', (err) => {//设置全局沉浸式windowStage.getMainWindow().then((win)=>{win.setWindowLayoutFullScreen(true)})});}

设置单一页面的 全屏

 //设置单一page的 全屏aboutToAppear(): void {window.getLastWindow(getContext()).then((win)=>{win.setWindowLayoutFullScreen(true)})}

获取状态栏 高度  顶部安全区高度

   //默认拿到是像素 需要转换成VPthis.safeTopHeight = px2vp(win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height)

获取底部导航栏高度   底部安全区高度

      this.safeBottomHeight =px2vp(win.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height)

单独控件和外层布局设置沉浸式

build() {Column(){Image($r('app.media.bg1_25612')).width('100%').height('100%').expandSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])}.width('100%').height('100%')}

设置为高斯模糊

build() {Column() {Image($r('app.media.bg1_25612')).width('50%').aspectRatio(1)}.width('100%').height('100%').backgroundImage($r('app.media.bg1_25612')).expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]).backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)}

键盘顶起

默认页面被顶的效果

这里写Mode 的时候记住一定是UI这个包里的

全局自适应

windowStage.loadContent('pages/day11/KeyBoardDemo', (err) => {windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE)});

效果

这里中部被压缩了  要求试图里必须有一个没有给固定高度的

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com