设置安全区

//方法1
async aboutToAppear():Promise<void>{
const win = await window.getLastWindow(getContext(this))
win.setWindowLayoutFullScreen(true)
}
//方法2
//底部若指定高度(如.height(100))会失效
Image('https://pic3.zhimg.com/v2-37617ef484856928d1db445d493a62f7_r.jpg?source=1940ef5c')
.height('100%')
.width('100%')
.expandSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])

获取安全区高度、宽度

async aboutToAppear():Promise<void>{
const win = await window.getLastWindow(getContext(this))
win.setWindowLayoutFullScreen(true)
//顶部高度window.AvoidAreaType.TYPE_SYSTEM
//底部window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR
//需要用px2vp转换px
this.topHeight = px2vp(win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height)
this.bottomHeight = px2vp(win.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height)
}
//使用
Column(){
Image('https://pic3.zhimg.com/v2-37617ef484856928d1db445d493a62f7_r.jpg?source=1940ef5c')
.height('100%')
.width('100%')
.expandSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])
}
.padding({top:this.topHeight,bottom:this.bottomHeight})
.width("100%")

问题

软键盘避让

弹出键盘时会把屏幕顶出去

//src/main/ets/entryability/EntryAbility.ets
async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
// const win = await window.getLastWindow(getContext(this))
// win.setWindowLayoutFullScreen(true)
//注意路径windowStage.loadContent('pages/Index',
windowStage.loadContent('pages/Index', (err) => {
//KeyboardAvoidMode是@kit.ArkUI的
windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE)
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
//pages/Index.ets
Column() {
TextInput({placeholder:this.message})
.layoutWeight(1)
.backgroundColor(Color.Pink)
Image('https://pic3.zhimg.com/v2-37617ef484856928d1db445d493a62f7_r.jpg?source=1940ef5c')
.height('80%')
.width('100%')
.expandSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])
}
// .padding({top:this.topHeight,bottom:this.bottomHeight})
.width("100%")