美文网首页
鸿蒙~弹窗基础 :promptAction

鸿蒙~弹窗基础 :promptAction

作者: 胡修波 | 来源:发表于2023-12-26 08:20 被阅读0次
  • 导入模块
import promptAction from '@ohos.promptAction'

一、文体提示 弹窗(类似:Android Toast): promptAction.showToast()

import promptAction from '@ohos.promptAction'

@Entry
@Component
struct RadioExample {
  build() {
    Row() {
      Button("1122")
        .onClick(() => {
          promptAction.showToast({message: "message", duration:3000, bottom:400})
        })
    }
  }
}

二、对话框 弹窗: promptAction.showDialog()

// xxx.ets
// xxx.ets
import promptAction from '@ohos.promptAction'

const TAG = "huxiubo"
@Entry
@Component
struct RadioExample {
  build() {
    Row() {
      Button("1122")
        .onClick(() => {
          promptAction.showDialog(
            {
              title: 'title',
              message:'message',
              buttons: [
                {
                  text: 'button1',
                  color: '#000000',
                },
                {
                  text: 'button2',
                  color: '#000000',
                }
              ]

            }
          )
            .then((data) => {
               console.info(TAG, `Successed:${JSON.stringify(data)}`);
            })
            .catch((err: Error) => {
              console.error(TAG,  `error: ${JSON.stringify(err)}`)
            })
        })
    }
  }
}

三、菜单 弹窗 : promptAction.showActionMenu

和 promptAction.showDialog 少了个 message:'message'

// xxx.ets
import promptAction from '@ohos.promptAction'

const TAG = "huxiubo"
@Entry
@Component
struct RadioExample {
  build() {
    Row() {
      Button("1122")
        .onClick(() => {
          promptAction.showActionMenu(
            {
              title: 'title',
              buttons: [
                {
                  text: 'button1',
                  color: '#000000',
                },
                {
                  text: 'button2',
                  color: '#000000',
                }
              ]

            }
          )
            .then((data) => {
               console.info(TAG, `Successed:${JSON.stringify(data)}`);
            })
            .catch((err: Error) => {
              console.error(TAG,  `error: ${JSON.stringify(err)}`)
            })
        })
    }
  }
}

相关文章

网友评论

      本文标题:鸿蒙~弹窗基础 :promptAction

      本文链接:https://www.haomeiwen.com/subject/vxdkndtx.html