中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何位TextInput设置长按弹出菜单?
微信扫码分享
@Entry @Component struct Index { controller: RichEditorController = new RichEditorController(); options: RichEditorOptions = { controller: this.controller }; build() { Column() { RichEditor(this.options) .onReady(() => { this.controller.addTextSpan('组件设置了自定义菜单,长按可触发。', { style: { fontColor: Color.Black, fontSize: 18 } }) }) .bindSelectionMenu(RichEditorSpanType.TEXT, this.SystemMenu, ResponseType.LongPress, { onDisappear: () => { } }) .width(300) .height(300) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } @Builder SystemMenu() { Column() { Menu() { if (this.controller) { MenuItemGroup() { MenuItem({ startIcon: $r("app.media.startIcon"), content: "剪切", labelInfo: "Ctrl+X", }).onClick(()=>{ this.controller.closeSelectionMenu() }) MenuItem({ startIcon: $r("app.media.startIcon"), content: "复制", labelInfo: "Ctrl+C" }) .onClick(()=>{ this.controller.closeSelectionMenu() }) MenuItem({ startIcon: $r("app.media.startIcon"), content: "粘贴", labelInfo: "Ctrl+V" }) .onClick(()=>{ this.controller.closeSelectionMenu() }) } } } .radius(10) .clip(true) .backgroundColor(Color.White) } } }