openharmony 鸿蒙 ohos-arkui-advanced-DownloadFileButton

2025-06-12 浏览 (11)

DownloadFileButton

DownloadFileButton is a download button that, when clicked, allows you to obtain the storage location of the current application in the public Download directory.

NOTE

This component is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { DownloadFileButton } from '@kit.ArkUI'

Child Components

Not supported

Attributes

The universal attributes are supported.

DownloadFileButton

Creates a download file button, which by default displays both an icon and text.

Decorator: @Component

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDecoratorDescription
contentOptionsDownloadContentOptionsYes@StateContent options for creating the download file button.
styleOptionsDownloadStyleOptionsYes@StateStyle options for creating the download file button.

DownloadContentOptions

Defines the content displayed in the download file button.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
iconDownloadIconStyleNoIcon style of the download file button.
If this parameter is not specified, no icon is contained. Either icon or text, or both, must be set.
textDownloadDescriptionNoText on the download file button.
If this parameter is not specified, no text is contained. Either icon or text, or both, must be set.

DownloadStyleOptions

Defines the style of the icon and text in the download file button.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
iconSizeDimensionNoIcon size of the download file button. The value cannot be in percentage.
Default value: 16vp
layoutDirectionDownloadLayoutDirectionNoDirection of the icon and text on the download file button.
Default value: DownloadLayoutDirection.HORIZONTAL
fontSizeDimensionNoFont size of the download file button. The value cannot be in percentage.
Default value: 16fp
fontStyleFontStyleNoFont style of the download file button.
Default value: FontStyle.Normal
fontWeightnumber |FontWeight |stringNoFont weight of the download file button. For the number type, the value ranges from 100 to 900, at an interval of 100. The default value is 400. A larger value indicates a heavier font weight. For the string type, only strings that represent a number, for example, 400, and the following enumerated values of FontWeight are supported: bold, bolder, lighter, regular, and medium.
Default value: FontWeight.Medium
fontFamilystring |ResourceNoFont family of the download file button.
Default font: 'HarmonyOS Sans'
fontColorResourceColorNoFont color of the download file button.
Default value: #ffffffff
iconColorResourceColorNoIcon color of the download file button.
Default value: #ffffffff
textIconSpaceDimensionNoSpace between the icon and text on the download file button.
Default value: 4vp

DownloadIconStyle

Defines the icon style of the download file button.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameValueDescription
FULL_FILLED1Filled style icon.
LINES2Line style icon.

DownloadDescription

Defines the text on the download file button.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameValueDescription
DOWNLOAD1The text on the download file button is Download.
DOWNLOAD_FILE2The text on the download file button is Download File.
SAVE3The text on the download file button is Save.
SAVE_IMAGE4The text on the download file button is Save Image.
SAVE_FILE5The text on the download file button is Save File.
DOWNLOAD_AND_SHARE6The text on the download file button is Download and Share.
RECEIVE7The text on the download file button is Receive.
CONTINUE_TO_RECEIVE8The text on the download file button is Continue.

DownloadLayoutDirection

Defines the direction of the icon and text in the download file button.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameValueDescription
HORIZONTAL0The icon and text on the download file button are horizontally arranged.
VERTICAL1The icon and text on the download file button are vertically arranged.

Events

The universal events are supported.

Example

// xxx.ets

import { picker } from '@kit.CoreFileKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { DownloadFileButton, DownloadLayoutDirection, DownloadIconStyle, DownloadDescription } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    Column() {
      DownloadFileButton({
        contentOptions: {
          icon: DownloadIconStyle.FULL_FILLED,
          text: DownloadDescription.DOWNLOAD
        },
        styleOptions: {
          iconSize: '16vp',
          layoutDirection: DownloadLayoutDirection.HORIZONTAL,
          fontSize: '16vp',
          fontStyle: FontStyle.Normal,
          fontWeight: FontWeight.Medium,
          fontFamily: 'HarmonyOS Sans',
          fontColor: '#ffffffff',
          iconColor: '#ffffffff',
          textIconSpace: '4vp'
        }
      })
        .backgroundColor('#007dff')
        .borderStyle(BorderStyle.Dotted)
        .borderWidth(0)
        .borderRadius('24vp')
        .position({ x: 0, y: 0 })
        .markAnchor({ x: 0, y: 0 })
        .offset({ x: 0, y: 0 })
        .constraintSize({})
        .padding({
          top: '12vp',
          bottom: '12vp',
          left: '24vp',
          right: '24vp'
        })
        .onClick(() => {
          this.downloadAction();
        })
    }
  }

  downloadAction() {
    try {
      const document = new picker.DocumentSaveOptions();
      document.pickerMode = picker.DocumentPickerMode.DOWNLOAD;
      new picker.DocumentViewPicker().save(document, (err: BusinessError, result: Array<string>) => {
        if (err) {
          return;
        }
        console.info(`downloadAction result:  ${JSON.stringify(result)}`);
      });
    } catch (e) {
    }
  }
}

en-us_image_0000001643320073

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙EditableTitleBar

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