openharmony 鸿蒙 ts-basic-components-menuitem

2025-06-12 浏览 (1)

MenuItem

The MenuItem component represents an item in a menu.

NOTE

This component is supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Child Components

Not supported

APIs

MenuItem(value?: MenuItemOptions|CustomBuilder)

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueMenuItemOptions |CustomBuilderNoInformation about the menu item.

MenuItemOptions

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
startIconResourceStrNoPath to the icon displayed on the left of the menu item.
Atomic service API: This API can be used in atomic services since API version 11.
contentResourceStrNoContent of the menu item.
Atomic service API: This API can be used in atomic services since API version 11.
endIconResourceStrNoPath to the icon displayed on the right of the menu item.
Atomic service API: This API can be used in atomic services since API version 11.
labelInfoResourceStrNoInformation about the ending label, for example, shortcut Ctrl+C.
Atomic service API: This API can be used in atomic services since API version 11.
builderCustomBuilderNoBuilder for a level-2 menu.
Atomic service API: This API can be used in atomic services since API version 11.
symbolStartIcon12+SymbolGlyphModifierNoPath to the symbol icon displayed on the left of the menu item. When this parameter is set, the icon set through startIcon is not displayed.
Atomic service API: This API can be used in atomic services since API version 12.
symbolEndIcon12+SymbolGlyphModifierNoPath to the symbol icon displayed on the right of the menu item. When this parameter is set, the icon set through endIcon is not displayed.
Atomic service API: This API can be used in atomic services since API version 12.

Attributes

In addition to the universal attributes, the following attributes are supported.

selected

selected(value: boolean)

Sets whether the menu item is selected.

Since API version 10, this attribute supports two-way binding through $$. Since API version 18, this attribute supports two-way binding through !!.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valuebooleanYesWhether the menu item is selected.
Default value: false
true: The menu item is selected.
false: The menu item is not selected.

selectIcon

selectIcon(value: boolean|ResourceStr|SymbolGlyphModifier)

Sets whether to display the selected icon when the menu item is selected.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueboolean |ResourceStr10+|SymbolGlyphModifier12+YesWhether to display the selected icon when the menu item is selected.
Default value: false
true: When the menu item is selected, the default tick icon is displayed.
false: When the menu item is selected, no icon is displayed.
ResourceStr: When the menu item is selected, the specified icon is displayed.
SymbolGlyphModifier: When the menu item is selected, the specified symbol icon is displayed.

contentFont10+

contentFont(value: Font)

Sets the font style of the menu item content.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueFontYesFont style of the menu item content.

contentFontColor10+

contentFontColor(value: ResourceColor)

Sets the font color of the menu item content.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueResourceColorYesFont color of the menu item content.
Default value: '#E5000000'

labelFont10+

labelFont(value: Font)

Sets the font style of the menu item label.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueFontYesFont style of the menu item label.

labelFontColor10+

labelFontColor(value: ResourceColor)

Sets the font color of the menu item label.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueResourceColorYesFont color of the menu item label.
Default value: '#99000000'

Events

onChange

onChange(callback: (selected: boolean) => void)

Triggered when the selection status of the menu item is changed manually.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
selectedbooleanYesInvoked when the selected status changes.
If the return value is true, the menu item is selected. If the return value is false, the menu item is not selected.

Example

See the example of Menu.

你可能感兴趣的鸿蒙文章

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/e1EOoo