1# Class (ContextMenuController) 2 3提供控制菜单关闭的能力。 4 5> **说明:** 6> 7> - 本模块首批接口从API version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8> 9> - 本Class首批接口从API version 12开始支持。 10> 11> - 以下API需先使用UIContext中的[getContextMenuController()](./arkts-apis-uicontext-uicontext.md#getcontextmenucontroller12)方法获取ContextMenuController实例,再通过此实例调用对应方法。 12 13## close<sup>12+</sup> 14 15close(): void 16 17关闭菜单。 18 19**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 20 21**系统能力:** SystemCapability.ArkUI.ArkUI.Full 22 23**示例:** 24 25通过定时器触发,调用ContextMenuController的close方法关闭菜单。 26 27```ts 28import { ContextMenuController } from '@kit.ArkUI'; 29 30@Entry 31@Component 32struct Index { 33 menu: ContextMenuController = this.getUIContext().getContextMenuController(); 34 35 @Builder MenuBuilder() { 36 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 37 Button('Test ContextMenu1 Close') 38 Divider().strokeWidth(2).margin(5).color(Color.Black) 39 Button('Test ContextMenu2') 40 Divider().strokeWidth(2).margin(5).color(Color.Black) 41 Button('Test ContextMenu3') 42 } 43 .width(200) 44 .height(160) 45 } 46 47 build() { 48 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 49 Button("启动定时器").onClick(()=> 50 { 51 setTimeout(() => { 52 this.menu.close(); 53 }, 10000); 54 }) 55 56 Column() { 57 Text("Test ContextMenu close") 58 .fontSize(20) 59 .width('100%') 60 .height(500) 61 .backgroundColor(0xAFEEEE) 62 .textAlign(TextAlign.Center) 63 } 64 .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) 65 } 66 .width('100%') 67 .height('100%') 68 } 69} 70``` 71 72 73 74