设置全局的沉浸式状态栏
在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)});
效果
这里中部被压缩了 要求试图里必须有一个没有给固定高度的