HarmonyOS鸿蒙Next中promptAction.showActionMenu接口支持布局为底部布局吗?

HarmonyOS鸿蒙Next中promptAction.showActionMenu接口支持布局为底部布局吗? promptAction.showActionMenu接口支持弹窗布局为底部布局吗?,看了下文档里不能设置对其方式,并且示例里也是居中的方式
[@ohos.promptAction (弹窗)-UI界面-ArkTS API-ArkUI(方舟UI框架)-应用框架 - 华为HarmonyOS开发者](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-V5#promptactionshowactionmenu)


更多关于HarmonyOS鸿蒙Next中promptAction.showActionMenu接口支持布局为底部布局吗?的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

可以测试一下底部布局。弹窗是出现在底部的。

[@ohos.promptAction (弹窗)-UI界面-ArkTS API-ArkUI(方舟UI框架)-应用框架 - 华为HarmonyOS开发者 (huawei.com)](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-V5#promptactionshowactionmenu)

如果不满足,看一下自定义弹窗。

参考链接

测试demo:

import promptAction from '[@ohos](/user/ohos).promptAction';
import { BusinessError } from '[@ohos](/user/ohos).base';

function showActionMenu() {
  try {
    promptAction.showActionMenu({
      title: 'Title Info',
      buttons: [
        {
          text: 'item1',
          color: '#666666'
        },
        {
          text: 'item2',
          color: '#000000'
        },
      ]
    }, (err, data) => {
      if (err) {
        console.info('showActionMenu err: ' + err);
        return;
      }
      console.info('showActionMenu success callback, click button: ' + data.index);
    })
  } catch (error) {
    let message = (error as BusinessError).message
    let code = (error as BusinessError).code
    console.error(`showActionMenu args error code is ${code}, message is ${message}`);
  }
  ;
}

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() =>{
          showActionMenu()
        })
    }
    .height('100%')
    .width('100%')
  }
}

更多关于HarmonyOS鸿蒙Next中promptAction.showActionMenu接口支持布局为底部布局吗?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,promptAction.showActionMenu接口默认支持多种布局方式,包括底部布局。该接口用于显示一个操作菜单,用户可以通过设置相关参数来控制菜单的显示位置和样式。具体的布局方式可以通过传入的配置参数进行调整,确保菜单能够以底部布局的形式呈现。开发者可以根据需求灵活使用该接口,实现不同的UI交互效果。

在HarmonyOS鸿蒙Next中,promptAction.showActionMenu接口目前主要支持弹出式菜单布局,默认显示在屏幕中央或指定位置。暂时不支持直接设置为底部布局。如果需要实现底部布局的菜单,建议使用CustomDialogBottomSheet等自定义组件来实现类似效果。

回到顶部