A context menu – a vertical list of items – can be bound to a component and displayed by long-pressing, clicking, or right-clicking the component. Menu control is applicable to scenarios where shortcut operations, setting options, or context-related operations are required. It provides users with convenient operation entries and improves the interaction experience of applications. The menu content and style can be customized to flexibly adapt to different service requirements.
The feature is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Multi-level menus cannot be displayed using bindMenu and bindContextMenu in CustomBuilder. Use the Menu component instead.
The text in the context menu cannot be selected by long-pressing.
When the window size changes or the menu content area is tapped, the menu is automatically hidden.
If the component bound to the menu is a draggable node and preview is not specified for bindContextMenu, the drag preview will be displayed when the menu is displayed, and the menu options and preview will not avoid each other. You can set preview or set the target node to be non-draggable based on the application scenario.
Since API version 12, menus allow users to display a submenu with a 500 ms long press, with the pressed state following the movement of the finger.
This feature is only available in scenarios where the Menu component is used and the child components include MenuItem or MenuItemGroup.
This feature is only available for menus with MenuPreviewMode set to NONE.
The maximum width of a menu is limited by the grids occupied by the device. Even if the width is set to 100%, the menu does not occupy the entire screen.
When the component object bound to the menu is destroyed, the menu disappears.
bindContextMenu can be displayed only in the subwindow. bindMenu can be configured to display in subwindows by setting the showInSubWindow property in MenuOptions.
type AnimationRange<T>=[from: T, to: T]
Sets the relative scale ratio at the start and end of the animation compared to the original preview image.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Atomic service API: This API can be used in atomic services since API version 12.
| Type | Description |
|---|---|
| [from: T, to: T] | from indicates the scale ratio at the beginning of the animation, and to indicates the scale ratio at the end of the animation. |
Enumerates the haptic feedback modes used when the menu is displayed.
Atomic service API: This API can be used in atomic services since API version 18.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| DISABLED | 0 | The menu is displayed without haptic feedback. |
| ENABLED | 1 | The menu is displayed with haptic feedback. |
| AUTO | 2 | Whether to enable haptic feedback is subject to system settings. It is enabled when the menu has a mask. |
type BorderRadiusType = Length | BorderRadiuses | LocalizedBorderRadiuses
Enumerates the border corner radius types.
Atomic service API: This API can be used in atomic services since API version 19.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Type | Description |
|---|---|
| Length | Size unit. |
| BorderRadiuses | Corner radius of a component's border. |
| LocalizedBorderRadiuses | Localized corner radius of a component's border. |
Enumerates modal modes of the sub-window menu.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| AUTO | 0 | Automatic mode, which is the default behavior of the menu component on the current device. In the current version, the effect on all devices is the same as that of ModalMode.NONE. |
| NONE | 1 | Events can be passed through areas other than the menu itself, allowing underlying controls to respond to events. |
| TARGET_WINDOW | 2 | Events cannot be passed through the application window where the menu is located and the menu area, but can be passed through other areas. |
Enumerates the scale modes of the preview image.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| AUTO | 0 | The preview image automatically adjusts its width, height, and scale based on Placement. |
| CONSTANT | 1 | The preview image retains its original size. However, the preview image may still be compressed or cropped due to the safe area constraints. |
| MAINTAIN | 2 | The preview image maintains its aspect ratio when scaled. |
Enumerates the reference sizes of the available layout area when the preview image width and height are set to percentages.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| SAFE_AREA | 0 | The reference size of the available layout area is the window size minus the safe margins on all sides. |
This example shows how to display a menu with symbol icons by setting symbolIcon in MenuElement of bindMenu.
import { SymbolGlyphModifier } from '@kit.ArkUI';
@Entry
@Component
struct MenuExample {
@State symbolIconModifier1: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_photo')).fontSize('24vp');
@State symbolIconModifier2: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_photo')).fontSize('24vp');
build() {
Column() {
Text('click for Menu')
}
.width('100%')
.margin({ top: 5 })
.bindMenu([
{
value: 'Menu1',
symbolIcon:this.symbolIconModifier1,
action: () => {
console.info('handle Menu1 select');
}
},
{
value: 'Menu2',
symbolIcon:this.symbolIconModifier2,
action: () => {
console.info('handle Menu2 select');
}
},
])
}
} 
This example demonstrates how to customize the background blur effect of a menu by setting the backgroundBlurStyleOptions property in ContextMenuOptions for bindMenu.
The backgroundBlurStyleOptions property is added to ContextMenuOptions since API version 18.
@Entry
@Component
struct MenuExample {
build() {
Stack() {
// Replace $r('app.media.bg') with the image resource file you use.
Image($r('app.media.bg'))
Column() {
Text('click for Menu')
.bindMenu([
{
value: 'Menu1',
action: () => {
console.info('handle Menu1 select')
}
},
{
value: 'Menu2',
action: () => {
console.info('handle Menu2 select')
}
},
],
{
backgroundBlurStyle: BlurStyle.BACKGROUND_THIN,
backgroundBlurStyleOptions: {
colorMode: ThemeColorMode.LIGHT,
blurOptions: { grayscale: [20, 20] },
policy: BlurStyleActivePolicy.ALWAYS_ACTIVE,
adaptiveColor: AdaptiveColor.AVERAGE,
scale: 1
},
}
)
}
.width('100%')
.margin({ top: 5 })
}
}
} 
This example demonstrates how to customize the background effect of a menu by setting the backgroundEffect property in ContextMenuOptions for bindMenu.
The backgroundEffect property is added to ContextMenuOptions since API version 18.
@Entry
@Component
struct MenuExample {
build() {
Stack() {
// Replace $r('app.media.bg') with the image resource file you use.
Image($r('app.media.bg'))
Column() {
Text('click for Menu')
.bindMenu([
{
value: 'Menu1',
action: () => {
console.info('handle Menu1 select');
}
},
{
value: 'Menu2',
action: () => {
console.info('handle Menu2 select');
}
},
],
{
backgroundBlurStyle: BlurStyle.BACKGROUND_THIN,
backgroundEffect: {
radius: 60,
saturation: 10,
brightness: 1,
color: '#661A1A1A',
adaptiveColor: AdaptiveColor.AVERAGE,
blurOptions:{grayscale:[20,20]}
}
}
)
}
.width('100%')
.margin({ top: 5 })
}
}
} 
This example demonstrates how to implement the function using bindContextMenu with responseType.LongPress set. In addition, the MenuPreviewMode type of the preview property in ContextMenuOptions is set to determine the menu preview mode. previewBorderRadius is set to implement the radius of the rounded corners of the preview image.
In API version 19, the previewBorderRadius property is added to ContextMenuOptions.
@Entry
@Component
struct Index {
// Replace $r('app.media.startIcon') with the image resource file you use.
private iconStr: ResourceStr = $r("app.media.startIcon");
@Builder
MyMenu() {
Menu() {
MenuItem({ startIcon: this.iconStr, content: "Menu option" })
MenuItem({ startIcon: this.iconStr, content: "Menu option" })
MenuItem({ startIcon: this.iconStr, content: "Menu option" })
}
}
build() {
Column({ space: 50 }) {
Column() {
Column() {
Text('preview-image')
.width(200)
.height(100)
.textAlign(TextAlign.Center)
.margin(100)
.fontSize(30)
.bindContextMenu(this.MyMenu, ResponseType.LongPress,
{
preview: MenuPreviewMode.IMAGE,
previewBorderRadius: 50
})
.backgroundColor("#ff7fcdff")
}
}.width('100%')
}
}
} 