HarmonyOS 自定义键盘不能顶起输入框

屏幕底部有一个输入框,使用自定义键盘,弹出键盘时不能顶起输入框,会遮住输入框,该如何设置才能使自定义键盘自动顶起输入框。

HarmonyOS
2024-10-29 11:10:40
465浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

​可以参考以下demo:

//EAbility中获取并缓存windowStage​。

onWindowStageCreate(windowStage: window.WindowStage): void {  
  
  AppStorage.setOrCreate("windowStage",windowStage);  
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');  
  
  windowStage.loadContent('pages/Index', (err, data) => {  
  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. Data: %{public}s', JSON.stringify(data) ?? '');  
});  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

//Index中

import window from '@ohos.window';  
import { KeyboardAvoidMode } from '@kit.ArkUI';  
  
@Entry  
@Component  
struct Index25 {  
  private windowStage = AppStorage.get("windowStage") as window.WindowStage  
  @State message:string = ''  
  
  
  aboutToAppear(): void {  
    // 设置虚拟键盘抬起时压缩页面大小为减去键盘的高度  
    this.windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE);  
  }  
  build() {  
    Column(){  
  
  
      Text(this.message).onClick(()=>{  
      }) .fontSize(30)  
  
  
      TextInput({text:'123123'})  
        .margin({bottom:30})  
    }.width('100%')  
    .height('100%')  
    .justifyContent(FlexAlign.SpaceBetween)  
  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
分享
微博
QQ
微信
回复
2024-10-29 17:27:29


相关问题
HarmonyOS 自定义键盘弹起后遮住输入框
1526浏览 • 1回复 待解决
HarmonyOS 自定义键盘输入框焦点问题
988浏览 • 1回复 待解决
HarmonyOS 键盘遮挡输入框
752浏览 • 1回复 待解决
HarmonyOS 输入框屏蔽系统键盘
692浏览 • 1回复 待解决
HarmonyOS 如何控制输入框弹出键盘
1031浏览 • 1回复 待解决
HarmonyOS 自定义不能全屏
942浏览 • 1回复 待解决
HarmonyOS webview里的输入框键盘覆盖
725浏览 • 1回复 待解决
HarmonyOS 输入框与软键盘问题
874浏览 • 1回复 待解决
HarmonyOS web中的输入框键盘遮住
752浏览 • 1回复 待解决
HarmonyOS Web输入框键盘mode模式问题
914浏览 • 1回复 待解决