harmony 鸿蒙@system.prompt (Prompt)

2022-08-09 浏览 (1121)

@system.prompt (Prompt)

The PromptAction module provides APIs for creating and showing toasts, dialog boxes, and action menus.

NOTE

  • The APIs of this module are deprecated since API version 8. You are advised to use @ohos.promptAction instead.

  • The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import prompt from '@system.prompt';

prompt.showToast

showToast(options: ShowToastOptions): void

Shows the toast.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
optionsShowToastOptionsYesOptions for showing the toast.

Example

import prompt from '@system.prompt';
class A{
  showToast() {
    prompt.showToast({
      message: 'Message Info',
      duration: 2000
    });
  }
}
export default new A()

prompt.showDialog

showDialog(options: ShowDialogOptions): void

Shows the dialog box.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
optionsShowDialogOptionsYesOptions for showing the dialog box.

Example

import prompt from '@system.prompt';
class B{
  showDialog() {
    prompt.showDialog({
      title: 'Title Info',
      message: 'Message Info',
      buttons: [
        {
          text: 'button',
          color: '#666666'
        },
      ],
      success: (data)=> {
        console.log('dialog success callback, click button : ' + data.index);
      },
      cancel: ()=> {
        console.log('dialog cancel callback');
      },
    });
  }
}
export default new B()

prompt.showActionMenu6+

showActionMenu(options: ShowActionMenuOptions): void

Shows the action menu.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
optionsShowActionMenuOptionsYesOptions for showing the action menu.

Example

import prompt from '@system.prompt';
class C{
  showActionMenu() {
    prompt.showActionMenu({
      title: 'Title Info',
      buttons: [
        {
          text: 'item1',
          color: '#666666'
        },
        {
          text: 'item2',
          color: '#000000'
        },
      ],
      success: (tapIndex)=> {
        console.log('dialog success callback, click button : ' + data.tapIndex);
      },
      fail: (errMsg)=> {
        console.log('dialog fail callback' + errMsg);
      },
    });
  }
}
export default new C()

ShowToastOptions

Describes the options for showing the toast.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
messagestringYesText to display.
durationnumberNoDuration that the toast will remain on the screen. The default value is 1500 ms. The recommended value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used.
bottom5+string|numberNoDistance between the toast border and the bottom of the screen.

Button

Defines the prompt information of a button.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
textstringYesText displayed on the button.
colorstringYesColor of the button.

ShowDialogSuccessResponse

Defines the dialog box response result.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
indexnumberYesData index.

ShowDialogOptions

Describes the options for showing the dialog box.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
titlestringNoTitle of the text to display.
messagestringNoText body.
buttons[Button, Button?, Button?]NoArray of buttons in the dialog box. The array structure is {text:'button', color: '#666666'}. One to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.
success(data: ShowDialogSuccessResponse) => voidNoCallback upon success.
cancel(data: string, code: string) => voidNoCallback upon failure.
complete(data: string) => voidNoCalled when the API call is complete.

ShowActionMenuOptions6+

Describes the options for showing the action menu.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
titlestringNoTitle of the text to display.
buttons[Button, Button?, Button?, Button?, Button?, Button?]YesArray of buttons in the dialog box. The array structure is {text:'button', color: '#666666'}. One to six buttons are supported.
success(tapIndex: number, errMsg: string) => voidNoInvoked when a dialog box is displayed.
fail(errMsg: string) => voidNoCallback upon failure.
complete(data: string) => voidNoInvoked when a dialog box is closed.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/e72c28b263d14392a80c19763f46673a