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%')
  }
}
分享
微博
QQ
微信
回复
2025-01-09 18:33:25
相关问题
HarmonyOS dialog软键盘
405浏览 • 1回复 待解决
HarmonyOS 弹窗布局软键盘压缩
179浏览 • 1回复 待解决
HarmonyOS 软键盘操作API
263浏览 • 1回复 待解决
HarmonyOS 软键盘问题
186浏览 • 1回复 待解决
HarmonyOS 软键盘弹出方式
382浏览 • 1回复 待解决
HarmonyOS TextInput软键盘监听
546浏览 • 1回复 待解决
HarmonyOS 如何监听软键盘收起
628浏览 • 1回复 待解决
HarmonyOS 如何监听软键盘弹出
522浏览 • 1回复 待解决