鸿蒙next-五种弹窗

一、有标题,内容,两个按钮

public static showAlertDialog(title: string, message: string, primaryButton: string, secondaryButton: string,
    callback: () => void, callback2: () => void) {
    AlertDialog.show({
      title: title,
      message: message,
      autoCancel: true,
      alignment: DialogAlignment.Center,
      offset: { dx: 0, dy: -20 },
      primaryButton: {
        value: primaryButton,
        action: callback
      },
      secondaryButton: {
        value: secondaryButton,
        action: callback2
      }
    })
    }

二、有标题,内容,一个按钮

public static showAlertDialogWithoutSecondaryButton(title: string, message: string, primaryButton: string,
      callback: () => void) {
      AlertDialog.show({
        title: title,
        message: message,
        autoCancel: true,
        alignment: DialogAlignment.Center,
        offset: { dx: 0, dy: -20 },
        primaryButton: {
          value: primaryButton,
          action: callback
        }
      })
    }

三、有标题,内容,无按钮

public static showAlertDialogWithoutButton(title: string, message: string) {
      AlertDialog.show({
        title: title,
        message: message,
        autoCancel: true,
        alignment: DialogAlignment.Center,
        offset: { dx: 0, dy: -20 },
      })
    }

四、无标题,有内容,一个按钮

public static showAlertDialogWithoutTitle(message: string, primaryButton: string,
      callback: () => void) {
      AlertDialog.show({
        message: message,
        autoCancel: true,
        alignment: DialogAlignment.Center,
        offset: { dx: 0, dy: -20 },
        primaryButton: {
          value: primaryButton,
          action: callback
        }
      })
    }

五、类似于android的Toast

public static showAlertDialogTimeout(message: string) {
        promptAction.showToast({
          message: message,
          duration: 2000
        });
    }

猜你喜欢

转载自blog.csdn.net/LIUCHANGSHUO/article/details/143346389