openharmony 鸿蒙 ts-universal-attributes-tips

2025-06-12 浏览 (1)

Tooltip Control

You can bind a floating tooltip to a component. The tooltip is automatically displayed when the cursor hovers over the component and hidden when the cursor moves away.

NOTE

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

bindTips

bindTips(message: TipsMessageType, options?: TipsOptions)

Binds a tooltip to the component.

NOTE

If the enable attribute of the bound component is set to false, the tooltip can still be displayed.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
messageTipsMessageTypeYesContent of the tooltip message.
optionsTipsOptionsNoParameters of the tooltip.
Default value:
{
appearingTime:700,
disappearingTime:300,
appearingTimeWithContinuousOperation: 300,
disappearingTimeWithContinuousOperation:0, enableArrow:true,
arrowPointPosition:ArrowPointPosition.CENTER,
arrowWidth:16vp,arrowHeight:8vp
}

TipsOptions

Defines the parameters of the tooltip.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
appearingTimenumberNoDelay before the tooltip appears.
Default value: 700.
Unit: ms.
disappearingTimenumberNoDelay before the tooltip disappears.
Default value: 300.
Unit: ms.
appearingTimeWithContinuousOperationnumberNoDelay before the tooltip disappears when multiple tooltips are displayed consecutively.
Default value: 300.
Unit: ms.
disappearingTimeWithContinuousOperationnumberNoDelay before the tooltip disappears when multiple tooltips are displayed consecutively.
Default value: 0.
Unit: ms.
enableArrowbooleanNoWhether to display the tooltip arrow.
Default value: true.
NOTE
If the available space on the screen is insufficient, the tooltip will cover part of the component and the arrow will not be displayed.
arrowPointPositionArrowPointPositionNoPosition of the tooltip arrow relative to its parent component. Available positions are Start, Center, and End, in both vertical and horizontal directions. These positions are within the parent component area and do not exceed its boundaries or cover rounded corners.
Default value: ArrowPointPosition.CENTER.
arrowWidthDimensionNoWidth of the tooltip arrow. If the arrow width exceeds the length of the edge minus twice the size of the tooltip rounded corner, the arrow is not drawn.
Default value: 16.
Unit: vp.
NOTE
Percentage values are not supported.
arrowHeightDimensionNoHeight of the tooltip arrow.
Default value: 8.
Unit: vp.
NOTE
Percentage values are not supported.

TipsMessageType

type TipsMessageType = ResourceStr|StyledString

Provides information about the tooltip.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

TypeDescription
ResourceStrType used to represent the types that can be used by input parameters of the string type.
StyledStringStyled string.

Example

Example 1: Binding a Tooltip

This example shows how to bind a tooltip to a button using bindTooltip.

// xxx.ets
@Entry
@Component
struct TipsExample {
  build() {
    Flex({ direction: FlexDirection.Column }) {
      Button('Hover Tips')
        .bindTips("test Tips", {
          appearingTime: 700,
          disappearingTime: 300,
          appearingTimeWithContinuousOperation: 300,
          disappearingTimeWithContinuousOperation: 0,
          enableArrow:true,
        })
        .position({ x: 100, y: 250 })
    }.width('100%').padding({ top: 5 })
  }
}

Example 2: Displaying and Hiding Multiple Tooltips

This example demonstrates how to configure multiple tooltips to appear and disappear in sequence using bindTips.

// xxx.ets

@Entry
@Component
struct TipsExample {
  build() {
    Flex({ direction: FlexDirection.Column }) {
      Button('Hover Tips')
        .bindTips("test Tips", {
          appearingTime: 700,
          disappearingTime: 300,
          appearingTimeWithContinuousOperation: 300,
          disappearingTimeWithContinuousOperation: 0,
          enableArrow:true,
        })
        .position({ x: 100, y: 250 })

      Button('Hover Tips')
        .bindTips("test Tips", {
          appearingTime: 700,
          disappearingTime: 300,
          appearingTimeWithContinuousOperation: 300,
          disappearingTimeWithContinuousOperation: 0,
          enableArrow:true,
        })
        .position({ x: 100, y: 350 })


    }.width('100%').padding({ top: 5 })
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

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