HarmonyOS promptAction.showActionMenu方法弹框位置不对?

使用api:

showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void 

进行弹窗,根据文档看是底部弹出的,但实际使用效果是居中弹出,看了下并没有参数可设置更改弹出位置;这个是否是bug? 有其它可替代的方法吗?

阅读 602
1 个回答

可以使用opencustomdialog,通过alignment或者offset来调整弹窗的位置。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-V5\#promptactionopencustomdialog11

import promptAction from '@ohos.promptAction'
let customDialogId: number = 0
@Builder
function customDialogBuilder() {
  Column() {
    Text('Custom dialog Message')
      .fontSize(10)
    Column() {
      Button('确认')
        .backgroundColor(Color.Transparent)
        .fontColor('#666666')
        .onClick(() => {
          promptAction.closeCustomDialog(customDialogId)
        })
      Blank()
        .width(50)
      Button('取消')
        .backgroundColor(Color.Transparent)
        .fontColor('#000000')
        .onClick(() => {
          promptAction.closeCustomDialog(customDialogId)
        })
    }
  }
  .height(200)
  .padding(5) }
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            promptAction.openCustomDialog({
              builder: customDialogBuilder.bind(this),
              alignment:DialogAlignment.Center,
              offset:{dx:0,dy:300} //可以通过这个属性来设置位置
            }).then((dialogId: number) => { customDialogId = dialogId })
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进