HarmonyOS dialog中触发软键盘把布局顶上去后还留有空白

HarmonyOS
2025-01-09 15:34:26
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

该间隙是dialog的规格问题,软键盘拉起后弹框和软键盘距离16vp导致的,可在弹窗位置设置.offset({ x: 0, y: 16 })即可,参考代码如下所示:

import { BusinessError } from '@kit.BasicServicesKit';
import { ComponentContent } from '@kit.ArkUI';

class Params {
  text: string = ""

  constructor(text: string) {
    this.text = text;
  }
}

@Builder
function buildText(params: Params) {
  Column() {
    TextInput({ placeholder: 'input your word...' })
      .placeholderColor(Color.Grey)
      .placeholderFont({ size: 14, weight: 400 })
      .caretColor(Color.Blue)
      .width('95%')
      .height(40)
      .margin(20)
      .fontSize(14)
      .fontColor(Color.Black)
  }
  .backgroundColor('#FFF0F0F0')
  .borderRadius(12)
  .height(350)
  .width('100%')
  .offset({ x: 0, y: 16 }) //弹窗位置,y等于16的时候刚刚好
}

@Entry
@Component
struct Index {
  @State message: string = "hello"

  build() {
    Row() {
      Column() {
        Button("click me")
          .onClick(() => {
            let uiContext = this.getUIContext();
            let promptAction = uiContext.getPromptAction();
            let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));
            try {
              promptAction.openCustomDialog(contentNode,
                { alignment: DialogAlignment.Bottom, offset: { dx: 0, dy: 0 } });
            } catch (error) {
              let message = (error as BusinessError).message;
              let code = (error as BusinessError).code;
              console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
            }
            ;
          })
      }
      .width('100%')
      .height('100%')
    }
    .height('100%')
  }
}
  • 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.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
分享
微博
QQ
微信
回复
2025-01-09 18:33:25
相关问题
HarmonyOS dialog软键盘
688浏览 • 1回复 待解决
HarmonyOS 弹窗布局软键盘压缩
569浏览 • 1回复 待解决
HarmonyOS 软键盘操作API
542浏览 • 1回复 待解决
HarmonyOS 软键盘问题
483浏览 • 1回复 待解决
HarmonyOS 软键盘弹出方式
860浏览 • 1回复 待解决
HarmonyOS TextInput软键盘监听
843浏览 • 1回复 待解决
鸿蒙软键盘弹出,页面底部的按钮
4905浏览 • 0回复 待解决