1# 菜单 2 3> **说明:** 4> 5> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 6 7## ContextMenu.close 8 9close(): void 10 11可以通过该方法在页面范围内关闭通过[bindContextMenu](./ts-universal-attributes-menu.md#属性)给组件绑定的菜单。 12 13## 示例 14 15```ts 16// xxx.ets 17@Entry 18@Component 19struct Index { 20 @Builder MenuBuilder() { 21 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 22 Button('Test ContextMenu1') 23 Divider().strokeWidth(2).margin(5) 24 Button('Test ContextMenu2') 25 Divider().strokeWidth(2).margin(5) 26 Button('Test ContextMenu3') 27 } 28 .width(200) 29 .height(160) 30 } 31 32 build() { 33 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 34 Column() { 35 Text("Test ContextMenu") 36 .fontSize(20) 37 .width('100%') 38 .height(500) 39 .backgroundColor(0xAFEEEE) 40 .textAlign(TextAlign.Center) 41 } 42 .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) 43 .onDragStart(() => { 44 // 拖拽时关闭菜单 45 ContextMenu.close() 46 }) 47 } 48 .width('100%') 49 .height('100%') 50 } 51} 52``` 53 54