#鸿蒙通关秘籍#使用 HarmonyNext 的 promptAction 显示居中提示文字的步骤有哪些?

HarmonyOS
2024-11-27 11:00:04
893浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
CodeCrafter

要在 HarmonyNext 中使用 promptAction 显示居中提示文字,步骤如下:

  • 导入 promptAction 以访问 showToast 方法。
import { promptAction } from '@kit.ArkUI';
  • 1.
  • 在界面布局中,定义按钮,通过 onClick 事件调用 showToast,并设置 alignment 参数为 Alignment.Center 实现居中显示。
import { promptAction } from '@kit.ArkUI';

@Entry
@Component
export struct ParticipateIn {
  @State textValue: string = '您没有该选项的权限';

  build() {
    Column() {
      Button('显示提示')
        .onClick(() => {
          promptAction.showToast({
            message: this.textValue,
            duration: 500,
            alignment: Alignment.Center
          });
        })
        .margin({ top: 25 })
    }.borderRadius(10).padding({ top: 25 })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
分享
微博
QQ
微信
回复
2024-11-27 11:10:10


相关问题