harmony 鸿蒙Types

2022-10-28 浏览 (1053)

Types

NOTE

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

Resource

The Resource type is used to reference resources for setting component attributes.

You can use $r or $rawfile to create a Resource object, but its attribute values cannot be changed.

  • $r('belonging.type.name')

    belonging: group to which the resource belongs, which can be 'sys' or 'app'.

    type: resource type, which can be 'boolean', 'color', 'float', 'intarray', 'integer', 'pattern', 'plural', 'strarray', 'string', or 'media'.

    name: resource name, which is determined during resource definition.

  • $rawfile('filename')

    filename: name of the file in the resources/rawfile directory of the project.

    NOTE

    When referencing resources of the Resource type, make sure the data type is the same as that of the attribute method. For example, if an attribute method supports the string|Resource types, the data type of the Resource type must be string.

Length

The Length type is used to represent a size unit.

TypeDescription
stringString type. Specify the length unit explicitly, for example, '10px', or provide the length in percentage, for example, '100%'.
numberNumber type. The default unit is vp.
ResourceSize referenced from system or application resources.

ResourceStr

The ResourceStr type is used to represent the types that can be used by input parameters of the string type.

TypeDescription
stringString type.
ResourceString referenced from system or application resources.

Padding

The Padding type is used to describe the paddings in different directions of a component.

NameTypeMandatoryDescription
topLengthNoHeight of the padding on the top of the component.
rightLengthNoWidth of the padding on the right of the component.
bottomLengthNoHeight of the padding at the bottom of the component.
leftLengthNoWidth of the padding on the left of the component.

Margin

The Margin type is used to describe the margins in different directions of a component.

NameTypeMandatoryDescription
topLengthNoHeight of the margin above the component.
rightLengthNoWidth of the margin on the right of the component.
bottomLengthNoHeight of the margin below the component.
leftLengthNoWidth of the margin on the left of the component.

EdgeWidths9+

The EdgeWidths type is used to describe the edge widths in different directions of a component.

NameTypeMandatoryDescription
topLengthNoWidth of the top edge of the component.
rightLengthNoWidth of the right edge of the component.
bottomLengthNoWidth of the bottom edge of the component.
leftLengthNoWidth of the left edge of the component.

BorderRadiuses9+

The BorderRadiuses type is used to describe the radius of the rounded corners of a component.

NameTypeMandatoryDescription
topLeftLengthNoRadius of the top left rounded corner of the component.
topRightLengthNoRadius of the top right rounded corner of the component.
bottomLeftLengthNoRadius of the bottom left rounded corner of the component.
bottomRightLengthNoRadius of the bottom right rounded corner of the component.

EdgeColors9+

The EdgeColors type is used to describe the edge colors of a component.

NameTypeMandatoryDescription
topResourceColorNoColor of the top edge of the component.
rightResourceColorNoColor of the right edge of the component.
bottomResourceColorNoColor of the bottom edge of the component.
leftResourceColorNoColor of the left edge of the component.

EdgeStyles9+

The EdgeStyles type is used to describe the edge styles of a component.

NameTypeMandatoryDescription
topBorderStyleNoStyle of the top edge of the component.
rightBorderStyleNoStyle of the right edge of the component.
bottomBorderStyleNoStyle of the bottom edge of the component.
leftBorderStyleNoStyle of the left edge of the component.

Offset

The Offset type is used to describe the offset coordinates of a component in the layout.

NameTypeMandatoryDescription
dxLengthYesX coordinate of the offset.
dyLengthYesY coordinate of the offset.

ResourceColor

The ResourceColor type is used to describe the color types of resources.

TypeDescription
ColorColor enums.
numberColor in hexadecimal notation. RGB is supported. Example: 0xffffff
stringColor in RGB or ARGB notation. Example: '#ffffff', '#ff000000', 'rgb(255, 100, 255)', 'rgba(255, 100, 255, 0.5)'
ResourceColor referenced from system or application resources.

ColoringStrategy

The ColoringStrategy type is used to describe the foreground colors.

NameDescription
INVERTInverse of the component background color.

LengthConstrain

The LengthConstrain type is used to describe the maximum and minimum lengths of a component.

NameTypeMandatoryDescription
minLengthLengthYesMinimum length of the component.
maxLengthLengthYesMaximum length of the component.

Font

The Font type is used to set the text style.

NameTypeMandatoryDescription
sizeLengthNoFont size. If the value is of the number type, the unit fp is used. The value cannot be a percentage.
Default value: 16.0
weightFontWeight |number |stringNoFont weight. For the number type, the value ranges from 100 to 900, at an interval of 100. A larger value indicates a thicker font.
Default value: 400 |FontWeight.Normal
familystring |ResourceNoFont family of the text. Use commas (,) to separate multiple fonts. The priority of the fonts is the sequence in which they are placed. An example value is 'Arial, HarmonyOS Sans'. The HarmonyOS Sans font and register custom fonts are supported.
styleFontStyleNoFont style.
Default value: FontStyle.Normal

Area8+

The Area type is used to describe the area information of a component.

NameTypeDescription
widthLengthWidth of the component. The value is of the number type in vp when used as the return value.
heightLengthHeight of the component. The value is of the number type in vp when used as the return value.
positionPositionPosition of the upper left corner of the component relative to that of its parent container.
globalPositionPositionPosition of the upper left corner of the component relative to that of the page where the component resides.

Position8+

The Position type is used to represent coordinates of a point.

NameTypeMandatoryDescription
xLengthNoX coordinate. The value is of the number type in vp when used as the return value.
yLengthNoY coordinate. The value is of the number type in vp when used as the return value.

ConstraintSizeOptions

The ConstraintSizeOptions type is used to set the size constraints of a component during component layout.

NameTypeMandatoryDescription
minWidthLengthNoMinimum width of the component.
maxWidthLengthNoMaximum width of the component.
minHeightLengthNoMinimum height of the component.
maxHeightLengthNoMaximum height of the component.

SizeOptions

The SizeOptions type is used to set the width and height.

NameTypeMandatoryDescription
widthLengthNoWidth of the component.
heightLengthNoHeight of the component.

BorderOptions

The BorderOptions type is used to provide border information.

NameTypeMandatoryDescription
widthLength |EdgeWidths9+NoBorder width.
colorResourceColor |EdgeColors9+NoBorder color.
radiusLength |BorderRadiuses9+NoRadius of the rounded corner border.
styleBorderStyle |EdgeStyles9+NoBorder style.

ColorFilter9+

The ColorFilter type is used to create a color filter with a 4 x 5 matrix.

NameTypeMandatoryDescription
constructornumber[]YesConstructor for creating a color filter with a 4 x 5 matrix. The input parameter is [m*n], which is the matrix value in row m and column n. The value range is [0, 1]. The matrix is row-first.

CustomBuilder8+

The CustomBuilder type is used to define custom UI descriptions in component attribute methods.

NameTypeDescription
CustomBuilder() => anyBuilder for creating a custom component; must be used with @Builder. For details, see @Builder.

PixelStretchEffectOptions10+

The PixelStretchEffectOptions type is used to describe the pixel stretch effect options.

NameTypeMandatoryDescription
leftLengthNoLength by which a pixel is stretched towards the left edge of the image.
rightLengthNoLength by which a pixel is stretched towards the right edge of the image.
topLengthNoLength by which a pixel is stretched towards the top edge of the image.
bottomLengthNoLength by which a pixel is stretched towards the bottom edge of the image.

ModalTransition10+

The ModalTransition type is used to set the transition type for a full-screen modal.

NameDescription
NONENo transition animation for the modal.
DEFAULTSlide-up and slide-down animation for the modal.
ALPHAOpacity gradient animation for the modal.

Dimension10+

The Length type is used to represent a size unit.

TypeDescription
PXPhysical pixel unit type. The unit px must be included, for example, '10px'.
VPPixel unit type specific to the screen density. The unit vp can be included or omitted, for example, 10 or '10vp'.
FPFont pixel unit type. The unit fp must be included, for example, '10fp'.
LPXLogical pixel unit type. The unit lpx must be included, for example, '10lpx'.
PercentagePercentage type. The unit % must be included, for example, '10%'.
ResourceSize referenced from system or application resources.

PX10+

The PX type is used to represent a length in px.

TypeDescription
{number}pxPhysical pixel unit type. The unit px must be included, for example, '10px'.

VP10+

The VP type is used to represent a length in vp.

TypeDescription
{number}vp|numberPixel unit type specific to the screen density. The unit vp can be included or omitted, for example, 10 or '10vp'.

FP10+

The FP type is used to represent a length in fp.

TypeDescription
{number}fpFont pixel unit type. The unit fp must be included, for example, '10fp'.

LPX10+

The LPX type is used to represent a length in lpx.

TypeDescription
{number}lpxLogical pixel unit type. The unit lpx must be included, for example, '10lpx'.

Percentage10+

The Percentage type is used to represent a length in percentage.

TypeDescription
{number}%Percentage type. The unit % must be included, for example, '10%'.

Degree10+

The Degree type is used to represent a length in deg.

TypeDescription
{number}degDegree type. The unit deg must be included, for example, '10deg'.

SwiperAnimationEvent10+

Describes the animation information of the <Swiper> component.

NameTypeDescription
currentOffsetnumberOffset of the currently displayed element relative to the start position of the <Swiper> along the main axis. Unit: vp
Default value: 0
targetOffsetnumberOffset of the target element relative to the start position of the <Swiper> along the main axis. Unit: vp
Default value: 0
velocitynumberHands-off velocity at the beginning of the animation. Unit: vp/s
Default value: 0

SafeAreaType10+

The SafeAreaType type is used to describe the types of expanded safe areas.

NameDescription
SYSTEMDefault non-safe area of the system, including the status bar and navigation bar.
CUTOUTNon-safe area of the device, for example, the notch area.
KEYBOARDSoft keyboard area.

SafeAreaEdge10+

The SafeAreaEdge type is used to define the edge for expanding the safe area.

NameDescription
TOPTop edge.
BOTTOMBottom edge.
STARTStart edge.
ENDEnd edge.

你可能感兴趣的鸿蒙文章

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/72168bbd4203481dbcf6e13ad1066cb7