#鸿蒙学习大百科#如何位TextInput设置长按弹出菜单?

如何位TextInput设置长按弹出菜单?

HarmonyOS
2024-10-26 09:14:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
自封的不算
@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)
    }
  }
}
分享
微博
QQ
微信
回复
2024-10-26 16:43:38
相关问题