#鸿蒙学习大百科#如何位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)
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
分享
微博
QQ
微信
回复
2024-10-26 16:43:38
相关问题
#鸿蒙学习大百科#ArkTS如何生成xml?
1236浏览 • 1回复 待解决