harmony 鸿蒙Action Sheet

2022-08-09 浏览 (1085)

Action Sheet

An action sheet is a dialog box that displays actions a user can take.

NOTE

The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.

The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see UIContext.

Since API version 10, you can use the showActionSheet API in UIContext to obtain the UI context.

ActionSheet.show

show(value: { title: string|Resource, subtitle: Resource, message: string|Resource, confirm?: {enabled?: boolean, defaultFocus?: boolean, style?: DialogButtonStyle, value: string|Resource, action:() => void}, cancel?:()=>void, sheets: Array<SheetInfo>, autoCancel?:boolean, alignment?: DialogAlignment, offset?: { dx: number|string|Resource; dy: number|string|Resource } })

Defines and shows the action sheet.

Parameters

NameTypeMandatoryDescription
titleResource |stringYesTitle of the dialog box.
subtitle10+ResourceStrNoSubtitle of the dialog box.
messageResource |stringYesContent of the dialog box.
autoCancelbooleanNoWhether to close the dialog box when the overlay is clicked.
Default value: true
The value true means to close the dialog box when the overlay is clicked, and false means the opposite.
confirm{
enabled10+?: boolean,
defaultFocus10+?: boolean,
style10+?: DialogButtonStyle,
value: ResourceStr,
action: () => void
}
NoInformation about the confirm button.
enabled: whether to respond when the button is clicked.
Default value: true
defaultFocus: whether the button is the default focus.
Default value: false
style: button style.
Default value: DialogButtonStyle.DEFAULT
value: button text.
action: callback upon button clicking.
cancel() => voidNoCallback invoked when the dialog box is closed after the overlay is clicked.
alignmentDialogAlignmentNoAlignment mode of the dialog box in the vertical direction.
Default value: DialogAlignment.Bottom
offset{
dx: Length,
dy: Length
}
NoOffset of the dialog box relative to the alignment position.{
dx: 0,
dy: 0
}
sheetsArray<SheetInfo>YesOptions in the dialog box. Each option supports the image, text, and callback.
maskRect10+RectangleNoMask area of the dialog box. Events outside the mask area are transparently transmitted, and events within the mask area are not.
Default value: { x: 0, y: 0, width: '100%', height: '100%' }

SheetInfo

NameTypeMandatoryDescription
titleResourceStrYesSheet text.
iconResourceStrNoSheet icon. By default, no icon is displayed.
action()=>voidYesCallback when the sheet is selected.

DialogButtonStyle10+

NameDescription.
DEFAULTBlue text on white background (black background under the dark theme).
HIGHLIGHTWhite text on blue background.

Example

@Entry
@Component
struct ActionSheetExample {
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Button('Click to Show ActionSheet')
        .onClick(() => {
          ActionSheet.show({
            title: 'ActionSheet title',
            subtitle: 'ActionSheet subtitle',
            message: 'message',
            autoCancel: true,
            confirm: {
              defaultFocus: true,
              value: 'Confirm button',
              action: () => {
                console.log('Get Alert Dialog handled')
              }
            },
            cancel: () => {
              console.log('actionSheet canceled')
            },
            alignment: DialogAlignment.Bottom,
            offset: { dx: 0, dy: -10 },
            sheets: [
              {
                title: 'apples',
                action: () => {
                  console.log('apples')
                }
              },
              {
                title: 'bananas',
                action: () => {
                  console.log('bananas')
                }
              },
              {
                title: 'pears',
                action: () => {
                  console.log('pears')
                }
              }
            ]
          })
        })
    }.width('100%')
    .height('100%')
  }
}

en-us_image_action

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkTS-based Declarative Development Paradigm

harmony 鸿蒙@ohos.multimedia.avCastPicker (AVCastPicker)

harmony 鸿蒙Property Animation

harmony 鸿蒙Enums

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

harmony 鸿蒙CheckboxGroup

harmony 鸿蒙DataPanel

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