ts-methods-menu.md 1.2 KB
Newer Older
E
esterzhou 已提交
1 2
# Menu

E
ester.zhou 已提交
3
The menu bound to a component through [bindContextMenu](./ts-universal-attributes-menu.md#atrributes) on a page can be closed as needed.
E
ester.zhou 已提交
4

E
ester.zhou 已提交
5
>  **NOTE**
E
ester.zhou 已提交
6
>
E
ester.zhou 已提交
7
>  The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
E
esterzhou 已提交
8

E
ester.zhou 已提交
9 10 11 12 13 14

## Required Permissions

None


E
esterzhou 已提交
15
## ContextMenu.close
E
ester.zhou 已提交
16 17
|Name|Description|
|----|---|
E
ester.zhou 已提交
18
| close(): void | Closes the menu bound to this component through [bindContextMenu](./ts-universal-attributes-menu.md#atrributes) on a page.|
E
esterzhou 已提交
19

E
ester.zhou 已提交
20 21 22 23

## Example

```ts
E
ester.zhou 已提交
24 25
// xxx.ets
@Entry
E
ester.zhou 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
@Component
struct Index {
  @Builder MenuBuilder() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Text('close')
        .fontSize(30)
        .fontWeight(FontWeight.Bold)
        .onClick(() => {
          ContextMenu.close();
        })
    }.height(400)
    .backgroundColor(Color.Pink)

  }

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) {
      Column() {
        Text("Text")
      }.bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
E
esterzhou 已提交
46
    }
E
ester.zhou 已提交
47 48
    .width('100%')
    .height('100%')
E
esterzhou 已提交
49
  }
E
ester.zhou 已提交
50
}
E
ester.zhou 已提交
51
```